@@ -48,33 +48,52 @@ The new bundle is called AcmeTestBundle, where the ``Acme`` portion is an exampl
4848name that should be replaced by some "vendor" name that represents you or your
4949organization (e.g. ABCTestBundle for some company named ``ABC ``).
5050
51- Start by creating a ``src/ Acme/TestBundle/ `` directory and adding a new file
51+ Start by creating a ``Acme/TestBundle/src / `` directory and adding a new file
5252called ``AcmeTestBundle.php ``::
5353
54- // src/ Acme/TestBundle/AcmeTestBundle.php
55- namespace App\ Acme\TestBundle;
54+ // Acme/TestBundle/src /AcmeTestBundle.php
55+ namespace Acme\TestBundle;
5656
57- use Symfony\Component\HttpKernel\Bundle\Bundle ;
57+ use Symfony\Component\HttpKernel\Bundle\AbstractBundle ;
5858
59- class AcmeTestBundle extends Bundle
59+ class AcmeTestBundle extends AbstractBundle
6060 {
6161 }
6262
63+ .. versionadded :: 6.1
64+
65+ The ``AbstractBundle `` was introduced in Symfony 6.1. If your bundle must be compatible
66+ with previous Symfony versions you have to extend from the :class: `Symfony\\ Component\\ HttpKernel\\ Bundle\\ Bundle `
67+ instead.
68+
6369.. tip ::
6470
6571 The name AcmeTestBundle follows the standard
6672 :ref: `Bundle naming conventions <bundles-naming-conventions >`. You could
6773 also choose to shorten the name of the bundle to simply TestBundle by naming
6874 this class TestBundle (and naming the file ``TestBundle.php ``).
6975
70- This empty class is the only piece you need to create the new bundle. Though
76+ It's recommended to place your bundle class in the ``src/ `` directory and keep out all the
77+ configuration files, templates, translations, etc. By default, Symfony determines the bundle path from the
78+ directory where the bundle class is placed, so you have to define the :method: `Symfony\\ Component\\ HttpKernel\\ Bundle\\ Bundle::getPath `
79+ method to tell Symfony what is the root directory of your bundle path::
80+
81+ class AcmeTestBundle extends AbstractBundle
82+ {
83+ public function getPath(): string
84+ {
85+ return \dirname(__DIR__);
86+ }
87+ }
88+
89+ This almost empty class is the only piece you need to create the new bundle. Though
7190commonly empty, this class is powerful and can be used to customize the behavior
7291of the bundle. Now that you've created the bundle, enable it::
7392
7493 // config/bundles.php
7594 return [
7695 // ...
77- App\ Acme\TestBundle\AcmeTestBundle::class => ['all' => true],
96+ Acme\TestBundle\AcmeTestBundle::class => ['all' => true],
7897 ];
7998
8099And while it doesn't do anything yet, AcmeTestBundle is now ready to be used.
@@ -86,26 +105,24 @@ The directory structure of a bundle is meant to help to keep code consistent
86105between all Symfony bundles. It follows a set of conventions, but is flexible
87106to be adjusted if needed:
88107
89- ``Controller/ ``
108+ ``src/ Controller/ ``
90109 Contains the controllers of the bundle (e.g. ``RandomController.php ``).
91110
92- ``DependencyInjection/ ``
93- Holds certain Dependency Injection Extension classes, which may import service
94- configuration, register compiler passes or more (this directory is not
95- necessary).
96-
97- ``Resources/config/ ``
111+ ``config/ ``
98112 Houses configuration, including routing configuration (e.g. ``routing.yaml ``).
99113
100- ``Resources/views/ ``
101- Holds templates organized by controller name (e.g. ``Random/index.html.twig ``).
114+ ``templates/ ``
115+ Holds templates organized by controller name (e.g. ``random/index.html.twig ``).
116+
117+ ``translations/ ``
118+ Holds translations organized by domain and locale (e.g. ``AcmeTestBundle.en.xlf ``).
102119
103- ``Resources/ public/ ``
120+ ``public/ ``
104121 Contains web assets (images, stylesheets, etc) and is copied or symbolically
105122 linked into the project ``public/ `` directory via the ``assets:install `` console
106123 command.
107124
108- ``Tests / ``
125+ ``tests / ``
109126 Holds all tests for the bundle.
110127
111128A bundle can be as small or large as the feature it implements. It contains
0 commit comments