@@ -68,30 +68,43 @@ The basic directory structure of an AcmeBlogBundle must read as follows:
68
68
.. code-block :: text
69
69
70
70
<your-bundle>/
71
- ├─ AcmeBlogBundle.php
72
- ├─ Controller/
73
- ├─ README.md
74
- ├─ LICENSE
75
- ├─ Resources/
76
- │ ├─ config/
77
- │ ├─ doc/
78
- │ │ └─ index.rst
79
- │ ├─ translations/
80
- │ ├─ views/
81
- │ └─ public/
82
- └─ Tests/
71
+ ├── config/
72
+ ├── docs/
73
+ │ └─ index.rst
74
+ ├── public/
75
+ ├── src/
76
+ │ ├── Controller/
77
+ │ ├── DependencyInjection/
78
+ │ └── AcmeBlogBundle.php
79
+ ├── templates/
80
+ ├── tests/
81
+ ├── translations/
82
+ ├── LICENSE
83
+ └── README.md
84
+
85
+ and the bundle path must be adjusted to the root directory:
86
+
87
+ .. code-block ::
88
+
89
+ class AcmeBlogBundle extends Bundle
90
+ {
91
+ public function getPath(): string
92
+ {
93
+ return \dirname(__DIR__);
94
+ }
95
+ }
83
96
84
97
**The following files are mandatory **, because they ensure a structure convention
85
98
that automated tools can rely on:
86
99
87
- * ``AcmeBlogBundle.php ``: This is the class that transforms a plain directory
100
+ * ``src/ AcmeBlogBundle.php ``: This is the class that transforms a plain directory
88
101
into a Symfony bundle (change this to your bundle's name);
89
102
* ``README.md ``: This file contains the basic description of the bundle and it
90
103
usually shows some basic examples and links to its full documentation (it
91
104
can use any of the markup formats supported by GitHub, such as ``README.rst ``);
92
105
* ``LICENSE ``: The full contents of the license used by the code. Most third-party
93
106
bundles are published under the MIT license, but you can `choose any license `_;
94
- * ``Resources/doc /index.rst ``: The root file for the Bundle documentation.
107
+ * ``docs /index.rst ``: The root file for the Bundle documentation.
95
108
96
109
The depth of subdirectories should be kept to a minimum for the most used
97
110
classes and files. Two levels is the maximum.
@@ -107,27 +120,27 @@ and others are just conventions followed by most developers):
107
120
=================================================== ========================================
108
121
Type Directory
109
122
=================================================== ========================================
110
- Commands ``Command/ ``
111
- Controllers ``Controller/ ``
112
- Service Container Extensions ``DependencyInjection/ ``
113
- Doctrine ORM entities (when not using annotations) ``Entity/ ``
114
- Doctrine ODM documents (when not using annotations) ``Document/ ``
115
- Event Listeners ``EventListener/ ``
116
- Configuration (routes, services, etc.) ``Resources/ config/ ``
117
- Web Assets (CSS, JS, images) ``Resources/ public/ ``
118
- Translation files ``Resources/ translations/ ``
119
- Validation (when not using annotations) ``Resources/ config/validation/ ``
120
- Serialization (when not using annotations) ``Resources/ config/serialization/ ``
121
- Templates ``Resources/views / ``
122
- Unit and Functional Tests ``Tests / ``
123
+ Commands ``src/ Command/ ``
124
+ Controllers ``src/ Controller/ ``
125
+ Service Container Extensions ``src/ DependencyInjection/ ``
126
+ Doctrine ORM entities (when not using annotations) ``src/ Entity/ ``
127
+ Doctrine ODM documents (when not using annotations) ``src/ Document/ ``
128
+ Event Listeners ``src/ EventListener/ ``
129
+ Configuration (routes, services, etc.) ``config/ ``
130
+ Web Assets (CSS, JS, images) ``public/ ``
131
+ Translation files ``translations/ ``
132
+ Validation (when not using annotations) ``config/validation/ ``
133
+ Serialization (when not using annotations) ``config/serialization/ ``
134
+ Templates ``templates / ``
135
+ Unit and Functional Tests ``tests / ``
123
136
=================================================== ========================================
124
137
125
138
Classes
126
139
-------
127
140
128
141
The bundle directory structure is used as the namespace hierarchy. For
129
142
instance, a ``ContentController `` controller which is stored in
130
- ``Acme/BlogBundle/Controller/ContentController.php `` would have the fully
143
+ ``Acme/BlogBundle/src/ Controller/ContentController.php `` would have the fully
131
144
qualified class name of ``Acme\BlogBundle\Controller\ContentController ``.
132
145
133
146
All classes and files must follow the :doc: `Symfony coding standards </contributing/code/standards >`.
@@ -153,7 +166,7 @@ Tests
153
166
-----
154
167
155
168
A bundle should come with a test suite written with PHPUnit and stored under
156
- the ``Tests / `` directory. Tests should follow the following principles:
169
+ the ``tests / `` directory. Tests should follow the following principles:
157
170
158
171
* The test suite must be executable with a simple ``phpunit `` command run from
159
172
a sample application;
@@ -240,10 +253,10 @@ Documentation
240
253
241
254
All classes and functions must come with full PHPDoc.
242
255
243
- Extensive documentation should also be provided in the ``Resources/doc / ``
256
+ Extensive documentation should also be provided in the ``docs / ``
244
257
directory.
245
- The index file (for example ``Resources/doc /index.rst `` or
246
- ``Resources/doc /index.md ``) is the only mandatory file and must be the entry
258
+ The index file (for example ``docs /index.rst `` or
259
+ ``docs /index.md ``) is the only mandatory file and must be the entry
247
260
point for the documentation. The
248
261
:doc: `reStructuredText (rST) </contributing/documentation/format >` is the format
249
262
used to render the documentation on the Symfony website.
@@ -480,9 +493,7 @@ The ``composer.json`` file should include at least the following metadata:
480
493
This information is used by Symfony to load the classes of the bundle. It's
481
494
recommended to use the `PSR-4 `_ autoload standard: use the namespace as key,
482
495
and the location of the bundle's main class (relative to ``composer.json ``)
483
- as value. For example, if the main class is located in the bundle root
484
- directory: ``"autoload": { "psr-4": { "SomeVendor\\BlogBundle\\": "" } } ``.
485
- If the main class is located in the ``src/ `` directory of the bundle:
496
+ as value. As the main class is located in the ``src/ `` directory of the bundle:
486
497
``"autoload": { "psr-4": { "SomeVendor\\BlogBundle\\": "src/" } } ``.
487
498
488
499
In order to make it easier for developers to find your bundle, register it on
@@ -493,14 +504,14 @@ Resources
493
504
494
505
If the bundle references any resources (config files, translation files, etc.),
495
506
don't use physical paths (e.g. ``__DIR__/config/services.xml ``) but logical
496
- paths (e.g. ``@FooBundle/Resources/ config/services.xml ``).
507
+ paths (e.g. ``@FooBundle/config/services.xml ``).
497
508
498
509
The logical paths are required because of the bundle overriding mechanism that
499
510
lets you override any resource/file of any bundle. See :ref: `http-kernel-resource-locator `
500
511
for more details about transforming physical paths into logical paths.
501
512
502
513
Beware that templates use a simplified version of the logical path shown above.
503
- For example, an ``index.html.twig `` template located in the ``Resources/views /Default/ ``
514
+ For example, an ``index.html.twig `` template located in the ``templates /Default/ ``
504
515
directory of the FooBundle, is referenced as ``@Foo/Default/index.html.twig ``.
505
516
506
517
Learn more
0 commit comments