Skip to content

Commit f17cf49

Browse files
committed
Some fixes for bundle best practices
1 parent a7cff0d commit f17cf49

File tree

1 file changed

+39
-57
lines changed

1 file changed

+39
-57
lines changed

cookbook/bundles/best_practices.rst

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ bundle class name must follow these simple rules:
4545

4646
Here are some valid bundle namespaces and class names:
4747

48-
+-----------------------------------+--------------------------+
49-
| Namespace | Bundle Class Name |
50-
+===================================+==========================+
51-
| ``Acme\Bundle\BlogBundle`` | ``AcmeBlogBundle`` |
52-
+-----------------------------------+--------------------------+
53-
| ``Acme\Bundle\Social\BlogBundle`` | ``AcmeSocialBlogBundle`` |
54-
+-----------------------------------+--------------------------+
55-
| ``Acme\BlogBundle`` | ``AcmeBlogBundle`` |
56-
+-----------------------------------+--------------------------+
48+
================================= ========================
49+
Namespace Bundle Class Name
50+
================================= ========================
51+
``Acme\Bundle\BlogBundle`` ``AcmeBlogBundle``
52+
``Acme\Bundle\Social\BlogBundle`` ``AcmeSocialBlogBundle``
53+
``Acme\BlogBundle`` ``AcmeBlogBundle``
54+
================================= ========================
5755

5856
By convention, the ``getName()`` method of the bundle class should return the
5957
class name.
@@ -83,22 +81,19 @@ The basic directory structure of a HelloBundle must read as follows:
8381

8482
.. code-block:: text
8583
86-
XXX/...
87-
HelloBundle/
88-
HelloBundle.php
89-
Controller/
90-
Resources/
91-
meta/
92-
LICENSE
93-
config/
94-
doc/
95-
index.rst
96-
translations/
97-
views/
98-
public/
99-
Tests/
100-
101-
The ``XXX`` directory(ies) reflects the namespace structure of the bundle.
84+
HelloBundle/
85+
├─ HelloBundle.php
86+
├─ Controller/
87+
├─ Resources/
88+
│ ├─ meta/
89+
│ │ └─ LICENSE
90+
│ ├─ config/
91+
│ ├─ doc/
92+
│ │ └─ index.rst
93+
│ ├─ translations/
94+
│ ├─ views/
95+
│ └─ public/
96+
└─ Tests/
10297
10398
The following files are mandatory:
10499

@@ -122,46 +117,38 @@ files are going to be part of the repository.
122117

123118
The following classes and files have specific emplacements:
124119

125-
+------------------------------+-----------------------------+
126-
| Type | Directory |
127-
+==============================+=============================+
128-
| Commands | ``Command/`` |
129-
+------------------------------+-----------------------------+
130-
| Controllers | ``Controller/`` |
131-
+------------------------------+-----------------------------+
132-
| Service Container Extensions | ``DependencyInjection/`` |
133-
+------------------------------+-----------------------------+
134-
| Event Listeners | ``EventListener/`` |
135-
+------------------------------+-----------------------------+
136-
| Configuration | ``Resources/config/`` |
137-
+------------------------------+-----------------------------+
138-
| Web Resources | ``Resources/public/`` |
139-
+------------------------------+-----------------------------+
140-
| Translation files | ``Resources/translations/`` |
141-
+------------------------------+-----------------------------+
142-
| Templates | ``Resources/views/`` |
143-
+------------------------------+-----------------------------+
144-
| Unit and Functional Tests | ``Tests/`` |
145-
+------------------------------+-----------------------------+
120+
============================ ===========================
121+
Type Directory
122+
============================ ===========================
123+
Commands ``Command/``
124+
Controllers ``Controller/``
125+
Service Container Extensions ``DependencyInjection/``
126+
Event Listeners ``EventListener/``
127+
Configuration ``Resources/config/``
128+
Web Resources ``Resources/public/``
129+
Translation files ``Resources/translations/``
130+
Templates ``Resources/views/``
131+
Tests ``Tests/``
132+
============================ ===========================
146133

147134
.. note::
148135

149136
When building a reusable bundle, model classes should be placed in the
150-
``Model`` namespace. See :doc:`/cookbook/doctrine/mapping_model_classes` for
137+
``Model`` namespace. See :doc:`/cookbook/doctrine/mapping_model_classes` on
151138
how to handle the mapping with a compiler pass.
152139

153140
Classes
154141
-------
155142

156143
The bundle directory structure is used as the namespace hierarchy. For
157144
instance, a ``HelloController`` controller is stored in
158-
``Bundle/HelloBundle/Controller/HelloController.php`` and the fully qualified
159-
class name is ``Bundle\HelloBundle\Controller\HelloController``.
145+
``HelloBundle/Controller/HelloController.php`` and the fully qualified
146+
class name is ``HelloBundle\Controller\HelloController``.
160147

161148
All classes and files must follow the Symfony coding :doc:`standards </contributing/code/standards>`.
162149

163150
Some classes should be seen as facades and should be as short as possible, like
164-
Commands, Helpers, Listeners, and Controllers.
151+
Commands, Helpers, Listeners and Controllers.
165152

166153
Classes that connect to the event dispatcher should be suffixed with
167154
``Listener``.
@@ -174,7 +161,7 @@ Vendors
174161
A bundle must not embed third-party PHP libraries. It should rely on the
175162
standard Symfony autoloading instead.
176163

177-
A bundle should not embed third-party libraries written in JavaScript, CSS, or
164+
A bundle should not embed third-party libraries written in JavaScript, CSS or
178165
any other language.
179166

180167
Tests
@@ -190,6 +177,7 @@ the ``Tests/`` directory. Tests should follow the following principles:
190177
* The tests should cover at least 95% of the code base.
191178

192179
.. note::
180+
193181
A test suite must not contain ``AllTests.php`` scripts, but must rely on the
194182
existence of a ``phpunit.xml.dist`` file.
195183

@@ -369,12 +357,6 @@ The end user can provide values in any configuration file:
369357
// app/config/config.php
370358
$container->setParameter('acme_hello.email.from', 'fabien@example.com');
371359
372-
.. code-block:: ini
373-
374-
; app/config/config.ini
375-
[parameters]
376-
acme_hello.email.from = fabien@example.com
377-
378360
Retrieve the configuration parameters in your code from the container::
379361

380362
$container->getParameter('acme_hello.email.from');

0 commit comments

Comments
 (0)