44Best Practices for Reusable Bundles
55===================================
66
7- There are 2 types of bundles:
7+ There are two types of bundles:
88
99* Application-specific bundles: only used to build your application;
1010* Reusable bundles: meant to be shared across many projects.
@@ -13,12 +13,8 @@ This article is all about how to structure your **reusable bundles** so that
1313they're easy to configure and extend. Many of these recommendations do not
1414apply to application bundles because you'll want to keep those as simple
1515as possible. For application bundles, just follow the practices shown throughout
16- the book and cookbook.
17-
18- .. seealso ::
19-
20- The best practices for application-specific bundles are discussed in
21- :doc: `/best_practices/introduction `.
16+ the :doc: `book </book/index >`, the :doc: `cookbook </cookbook/index >` and the
17+ :doc: `best practices </best_practices/index >` book.
2218
2319.. index ::
2420 pair: Bundle; Naming conventions
@@ -38,7 +34,7 @@ bundle class name must follow these simple rules:
3834
3935* Use only alphanumeric characters and underscores;
4036* Use a CamelCased name;
41- * Use a descriptive and short name (no more than 2 words);
37+ * Use a descriptive and short name (no more than two words);
4238* Prefix the name with the concatenation of the vendor (and optionally the
4339 category namespaces);
4440* Suffix the name with ``Bundle ``.
@@ -112,7 +108,7 @@ The following files are mandatory:
112108 structure to work.
113109
114110The depth of sub-directories should be kept to the minimal for most used
115- classes and files (2 levels at a maximum). More levels can be defined for
111+ classes and files (two levels at a maximum). More levels can be defined for
116112non-strategic, less-used files.
117113
118114The bundle directory is read-only. If you need to write temporary files, store
@@ -158,7 +154,7 @@ instance, a ``HelloController`` controller is stored in
158154``Bundle/HelloBundle/Controller/HelloController.php `` and the fully qualified
159155class name is ``Bundle\HelloBundle\Controller\HelloController ``.
160156
161- All classes and files must follow the Symfony coding :doc: `standards </contributing/code/standards >`.
157+ All classes and files must follow the :doc: `Symfony coding standards </contributing/code/standards >`.
162158
163159Some classes should be seen as facades and should be as short as possible, like
164160Commands, Helpers, Listeners, and Controllers.
@@ -181,7 +177,7 @@ Tests
181177-----
182178
183179A bundle should come with a test suite written with PHPUnit and stored under
184- the ``Tests/ `` directory. Tests should follow the following principles:
180+ the ``Tests/ `` directory. Tests should follow these principles:
185181
186182* The test suite must be executable with a simple ``phpunit `` command run from
187183 a sample application;
@@ -190,13 +186,14 @@ the ``Tests/`` directory. Tests should follow the following principles:
190186* The tests should cover at least 95% of the code base.
191187
192188.. note ::
189+
193190 A test suite must not contain ``AllTests.php `` scripts, but must rely on the
194191 existence of a ``phpunit.xml.dist `` file.
195192
196193Documentation
197194-------------
198195
199- All classes and functions must come with full PHPDoc.
196+ All classes and functions must be fully documented using ` PHPDoc `_ tags .
200197
201198Extensive documentation should also be provided in the
202199:doc: `reStructuredText </contributing/documentation/format >` format, under
@@ -233,8 +230,8 @@ following standardized instructions in your ``README.md`` file.
233230 Step 2: Enable the Bundle
234231 -------------------------
235232
236- Then, enable the bundle by adding the following line in the `app/AppKernel.php`
237- file of your project:
233+ Then, enable the bundle by adding it to the list of registered bundles
234+ in the `app/AppKernel.php` file of your project:
238235
239236 ```php
240237 <?php
@@ -279,8 +276,8 @@ following standardized instructions in your ``README.md`` file.
279276 Step 2: Enable the Bundle
280277 -------------------------
281278
282- Then, enable the bundle by adding the following line in the ``app/AppKernel.php``
283- file of your project:
279+ Then, enable the bundle by adding it to the list of registered bundles
280+ in the ``app/AppKernel.php`` file of your project:
284281
285282 .. code-block:: php
286283
@@ -306,8 +303,11 @@ following standardized instructions in your ``README.md`` file.
306303
307304 .. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
308305
309- This template assumes that your bundle is in its ``1.x `` version. If not, change
310- the ``"~1" `` installation version accordingly (``"~2" ``, ``"~3" ``, etc.)
306+ The example above assumes that you are installing the latest stable version of
307+ the bundle, where you don't have to provide the package version number
308+ (e.g. ``composer require friendsofsymfony/user-bundle ``). If the installation
309+ instructions refer to some past bundle version or to some unstable version,
310+ include the version constraint (e.g. ``composer require friendsofsymfony/user-bundle "~2.0@dev" ``).
311311
312312Optionally, you can add more installation steps (*Step 3 *, *Step 4 *, etc.) to
313313explain other required installation tasks, such as registering routes or
@@ -330,7 +330,8 @@ Translation Files
330330-----------------
331331
332332If a bundle provides message translations, they must be defined in the XLIFF
333- format; the domain should be named after the bundle name (``bundle.hello ``).
333+ format; the :ref: `translation domain <using-message-domains >` should be named
334+ after the bundle name (``bundle.hello ``).
334335
335336A bundle must not override existing messages from another bundle.
336337
@@ -369,18 +370,12 @@ The end user can provide values in any configuration file:
369370 // app/config/config.php
370371 $container->setParameter('acme_hello.email.from', 'fabien@example.com');
371372
372- .. code-block :: ini
373-
374- ; app/config/config.ini
375- [parameters]
376- acme_hello.email.from = fabien@example.com
377-
378373 Retrieve the configuration parameters in your code from the container::
379374
380375 $container->getParameter('acme_hello.email.from');
381376
382377Even if this mechanism is simple enough, you are highly encouraged to use the
383- semantic configuration described in the cookbook.
378+ :doc: ` semantic bundle configuration < / cookbook/bundles/extension >` instead .
384379
385380.. note ::
386381
@@ -435,3 +430,4 @@ Learn more from the Cookbook
435430* :doc: `/cookbook/bundles/extension `
436431
437432.. _standards : http://www.php-fig.org/psr/psr-4/
433+ .. _`PHPDoc` : https://en.wikipedia.org/wiki/PHPDoc
0 commit comments