@@ -82,7 +82,7 @@ method to tell Symfony what is the root directory of your bundle path::
82
82
{
83
83
public function getPath(): string
84
84
{
85
- return \dirname(__DIR__);
85
+ return \dirname(__DIR__); // returns /path/to/Acme/TestBundle/
86
86
}
87
87
}
88
88
@@ -105,8 +105,8 @@ The directory structure of a bundle is meant to help to keep code consistent
105
105
between all Symfony bundles. It follows a set of conventions, but is flexible
106
106
to be adjusted if needed:
107
107
108
- ``src/Controller/ ``
109
- Contains the controllers of the bundle (e.g. ``RandomController.php ``).
108
+ ``src/ ``
109
+ Contains mainly PHP classes related to the bundle logic (e.g. ``Controller/ RandomController.php ``).
110
110
111
111
``config/ ``
112
112
Houses configuration, including routing configuration (e.g. ``routing.yaml ``).
@@ -125,6 +125,25 @@ to be adjusted if needed:
125
125
``tests/ ``
126
126
Holds all tests for the bundle.
127
127
128
+ It's recommended to use the `PSR-4 `_ autoload standard: use the namespace as key,
129
+ and the location of the bundle's main class (relative to ``composer.json ``)
130
+ as value. As the main class is located in the ``src/ `` directory of the bundle:
131
+
132
+ .. code-block :: json
133
+
134
+ {
135
+ "autoload" : {
136
+ "psr-4" : {
137
+ "Acme\\ TestBundle\\ " : " src/"
138
+ }
139
+ },
140
+ "autoload-dev" : {
141
+ "psr-4" : {
142
+ "Acme\\ TestBundle\\ Tests\\ " : " tests/"
143
+ }
144
+ }
145
+ }
146
+
128
147
A bundle can be as small or large as the feature it implements. It contains
129
148
only the files you need and nothing else.
130
149
@@ -143,3 +162,4 @@ Learn more
143
162
* :doc: `/bundles/prepend_extension `
144
163
145
164
.. _`third-party bundles` : https://github.com/search?q=topic%3Asymfony-bundle&type=Repositories
165
+ .. _`PSR-4` : https://www.php-fig.org/psr/psr-4/
0 commit comments