4
4
Best Practices for Reusable Bundles
5
5
===================================
6
6
7
- There are 2 types of bundles:
7
+ There are two types of bundles:
8
8
9
9
* Application-specific bundles: only used to build your application;
10
10
* 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
13
13
they're easy to configure and extend. Many of these recommendations do not
14
14
apply to application bundles because you'll want to keep those as simple
15
15
as 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.
22
18
23
19
.. index ::
24
20
pair: Bundle; Naming conventions
@@ -38,7 +34,7 @@ bundle class name must follow these simple rules:
38
34
39
35
* Use only alphanumeric characters and underscores;
40
36
* 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);
42
38
* Prefix the name with the concatenation of the vendor (and optionally the
43
39
category namespaces);
44
40
* Suffix the name with ``Bundle ``.
@@ -112,7 +108,7 @@ The following files are mandatory:
112
108
structure to work.
113
109
114
110
The 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
116
112
non-strategic, less-used files.
117
113
118
114
The bundle directory is read-only. If you need to write temporary files, store
@@ -158,7 +154,7 @@ instance, a ``HelloController`` controller is stored in
158
154
``Bundle/HelloBundle/Controller/HelloController.php `` and the fully qualified
159
155
class name is ``Bundle\HelloBundle\Controller\HelloController ``.
160
156
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 >`.
162
158
163
159
Some classes should be seen as facades and should be as short as possible, like
164
160
Commands, Helpers, Listeners, and Controllers.
@@ -181,7 +177,7 @@ Tests
181
177
-----
182
178
183
179
A 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:
185
181
186
182
* The test suite must be executable with a simple ``phpunit `` command run from
187
183
a sample application;
@@ -190,13 +186,14 @@ the ``Tests/`` directory. Tests should follow the following principles:
190
186
* The tests should cover at least 95% of the code base.
191
187
192
188
.. note ::
189
+
193
190
A test suite must not contain ``AllTests.php `` scripts, but must rely on the
194
191
existence of a ``phpunit.xml.dist `` file.
195
192
196
193
Documentation
197
194
-------------
198
195
199
- All classes and functions must come with full PHPDoc .
196
+ All classes and functions must be fully documented using ` phpDocumentor `_ tags .
200
197
201
198
Extensive documentation should also be provided in the
202
199
:doc: `reStructuredText </contributing/documentation/format >` format, under
@@ -306,9 +303,6 @@ following standardized instructions in your ``README.md`` file.
306
303
307
304
.. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
308
305
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.)
311
-
312
306
Optionally, you can add more installation steps (*Step 3 *, *Step 4 *, etc.) to
313
307
explain other required installation tasks, such as registering routes or
314
308
dumping assets.
@@ -330,7 +324,8 @@ Translation Files
330
324
-----------------
331
325
332
326
If 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 ``).
327
+ format; the :ref: `translation domain <using-message-domains >` should be named
328
+ after the bundle name (``bundle.hello ``).
334
329
335
330
A bundle must not override existing messages from another bundle.
336
331
@@ -369,27 +364,17 @@ The end user can provide values in any configuration file:
369
364
// app/config/config.php
370
365
$container->setParameter('acme_hello.email.from', 'fabien@example.com');
371
366
372
- .. code-block :: ini
373
-
374
- ; app/config/config.ini
375
- [parameters]
376
- acme_hello.email.from = fabien@example.com
377
-
378
367
Retrieve the configuration parameters in your code from the container::
379
368
380
369
$container->getParameter('acme_hello.email.from');
381
370
382
371
Even if this mechanism is simple enough, you are highly encouraged to use the
383
- semantic configuration described in the cookbook.
372
+ :doc: ` semantic bundle configuration < / cookbook/bundles/extension >` instead .
384
373
385
374
.. note ::
386
375
387
376
If you are defining services, they should also be prefixed with the bundle
388
377
alias.
389
378
390
- Learn more from the Cookbook
391
- ----------------------------
392
-
393
- * :doc: `/cookbook/bundles/extension `
394
-
395
- .. _standards : http://www.php-fig.org/psr/psr-4/
379
+ .. _`standards` : http://www.php-fig.org/psr/psr-0/
380
+ .. _`phpDocumentor` : http://www.phpdoc.org/
0 commit comments