8000 Update bundle.rst · symfony/symfony-docs@c2c47a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2c47a2

Browse files
committed
Update bundle.rst
1 parent c93db0b commit c2c47a2

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

bundles.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ method to tell Symfony what is the root directory of your bundle path::
8282
{
8383
public function getPath(): string
8484
{
85-
return \dirname(__DIR__);
85+
return \dirname(__DIR__); // returns /path/to/Acme/TestBundle/
8686
}
8787
}
8888

@@ -105,8 +105,8 @@ The directory structure of a bundle is meant to help to keep code consistent
105105
between all Symfony bundles. It follows a set of conventions, but is flexible
106106
to be adjusted if needed:
107107

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``).
110110

111111
``config/``
112112
Houses configuration, including routing configuration (e.g. ``routing.yaml``).
@@ -125,6 +125,25 @@ to be adjusted if needed:
125125
``tests/``
126126
Holds all tests for the bundle.
127127

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+
128147
A bundle can be as small or large as the feature it implements. It contains
129148
only the files you need and nothing else.
130149

@@ -143,3 +162,4 @@ Learn more
143162
* :doc:`/bundles/prepend_extension`
144163

145164
.. _`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

Comments
 (0)
0