Skip to content

Commit 2ec2171

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Bundle] Sync doc pages with current Symfony codebase
2 parents ba3f9f1 + 64bb6d8 commit 2ec2171

File tree

4 files changed

+54
-48
lines changed

4 files changed

+54
-48
lines changed

bundles.rst

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ file::
2222
return [
2323
// 'all' means that the bundle is enabled for any Symfony environment
2424
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
25-
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
26-
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
27-
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
28-
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
25+
// ...
26+
27+
// this bundle is enabled only in 'dev'
28+
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
29+
// ...
30+
2931
// this bundle is enabled only in 'dev' and 'test', so you can't use it in 'prod'
3032
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
33+
// ...
3134
];
3235

3336
.. tip::
@@ -40,18 +43,18 @@ Creating a Bundle
4043
-----------------
4144

4245
This section creates and enables a new bundle to show there are only a few steps required.
43-
The new bundle is called AcmeTestBundle, where the ``Acme`` portion is an example
46+
The new bundle is called AcmeBlogBundle, where the ``Acme`` portion is an example
4447
name that should be replaced by some "vendor" name that represents you or your
45-
organization (e.g. AbcTestBundle for some company named ``Abc``).
48+
organization (e.g. AbcBlogBundle for some company named ``Abc``).
4649

47-
Start by creating a new class called ``AcmeTestBundle``::
50+
Start by creating a new class called ``AcmeBlogBundle``::
4851

49-
// src/AcmeTestBundle.php
50-
namespace Acme\TestBundle;
52+
// src/AcmeBlogBundle.php
53+
namespace Acme\BlogBundle;
5154

5255
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
5356

54-
class AcmeTestBundle extends AbstractBundle
57+
class AcmeBlogBundle extends AbstractBundle
5558
{
5659
}
5760

@@ -62,10 +65,10 @@ Start by creating a new class called ``AcmeTestBundle``::
6265

6366
.. tip::
6467

65-
The name AcmeTestBundle follows the standard
68+
The name AcmeBlogBundle follows the standard
6669
:ref:`Bundle naming conventions <bundles-naming-conventions>`. You could
67-
also choose to shorten the name of the bundle to simply TestBundle by naming
68-
this class TestBundle (and naming the file ``TestBundle.php``).
70+
also choose to shorten the name of the bundle to simply BlogBundle by naming
71+
this class BlogBundle (and naming the file ``BlogBundle.php``).
6972

7073
This empty class is the only piece you need to create the new bundle. Though
7174
commonly empty, this class is powerful and can be used to customize the behavior
@@ -74,10 +77,10 @@ of the bundle. Now that you've created the bundle, enable it::
7477
// config/bundles.php
7578
return [
7679
// ...
77-
Acme\TestBundle\AcmeTestBundle::class => ['all' => true],
80+
Acme\BlogBundle\AcmeBlogBundle::class => ['all' => true],
7881
];
7982

80-
And while it doesn't do anything yet, AcmeTestBundle is now ready to be used.
83+
And while it doesn't do anything yet, AcmeBlogBundle is now ready to be used.
8184

8285
Bundle Directory Structure
8386
--------------------------
@@ -86,31 +89,31 @@ The directory structure of a bundle is meant to help to keep code consistent
8689
between all Symfony bundles. It follows a set of conventions, but is flexible
8790
to be adjusted if needed:
8891

89-
``src/``
90-
Contains all PHP classes related to the bundle logic (e.g. ``Controller/RandomController.php``).
92+
``assets/``
93+
Contains the web asset sources like JavaScript and TypeScript files, CSS and
94+
Sass files, but also images and other assets related to the bundle that are
95+
not in ``public/`` (e.g. Stimulus controllers).
9196

9297
``config/``
93-
Houses configuration, including routing configuration (e.g. ``routing.yaml``).
94-
95-
``templates/``
96-
Holds templates organized by controller name (e.g. ``random/index.html.twig``).
97-
98-
``translations/``
99-
Holds translations organized by domain and locale (e.g. ``AcmeTestBundle.en.xlf``).
98+
Houses configuration, including routing configuration (e.g. ``routes.php``).
10099

101100
``public/``
102101
Contains web assets (images, compiled CSS and JavaScript files, etc.) and is
103102
copied or symbolically linked into the project ``public/`` directory via the
104103
``assets:install`` console command.
105104

106-
``assets/``
107-
Contains the web asset sources (JavaScript and TypeScript files, CSS and Sass
108-
files, etc.), images and other assets related to the bundle that are not in
109-
``public/`` (e.g. Stimulus controllers)
105+
``src/``
106+
Contains all PHP classes related to the bundle logic (e.g. ``Controller/CategoryController.php``).
107+
108+
``templates/``
109+
Holds templates organized by controller name (e.g. ``category/show.html.twig``).
110110

111111
``tests/``
112112
Holds all tests for the bundle.
113113

114+
``translations/``
115+
Holds translations organized by domain and locale (e.g. ``AcmeBlogBundle.en.xlf``).
116+
114117
.. caution::
115118

116119
The recommended bundle structure was changed in Symfony 5, read the
@@ -121,7 +124,7 @@ to be adjusted if needed:
121124
new structure. Override the ``Bundle::getPath()`` method to change to
122125
the old structure::
123126

124-
class AcmeTestBundle extends AbstractBundle
127+
class AcmeBlogBundle extends AbstractBundle
125128
{
126129
public function getPath(): string
127130
{
@@ -140,12 +143,12 @@ to be adjusted if needed:
140143
{
141144
"autoload": {
142145
"psr-4": {
143-
"Acme\\TestBundle\\": "src/"
146+
"Acme\\BlogBundle\\": "src/"
144147
}
145148
},
146149
"autoload-dev": {
147150
"psr-4": {
148-
"Acme\\TestBundle\\Tests\\": "tests/"
151+
"Acme\\BlogBundle\\Tests\\": "tests/"
149152
}
150153
}
151154
}

bundles/configuration.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ of your bundle's configuration.
175175

176176
The ``Configuration`` class to handle the sample configuration looks like::
177177

178-
// src/Acme/SocialBundle/DependencyInjection/Configuration.php
178+
// src/DependencyInjection/Configuration.php
179179
namespace Acme\SocialBundle\DependencyInjection;
180180

181181
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -216,7 +216,7 @@ This class can now be used in your ``load()`` method to merge configurations and
216216
force validation (e.g. if an additional option was passed, an exception will be
217217
thrown)::
218218

219-
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
219+
// src/DependencyInjection/AcmeSocialExtension.php
220220
public function load(array $configs, ContainerBuilder $container): void
221221
{
222222
$configuration = new Configuration();
@@ -236,7 +236,7 @@ For example, imagine your bundle has the following example config:
236236

237237
.. code-block:: xml
238238
239-
<!-- src/Acme/SocialBundle/Resources/config/services.xml -->
239+
<!-- src/config/services.xml -->
240240
<?xml version="1.0" encoding="UTF-8" ?>
241241
<container xmlns="http://symfony.com/schema/dic/services"
242242
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -253,8 +253,8 @@ For example, imagine your bundle has the following example config:
253253
254254
In your extension, you can load this and dynamically set its arguments::
255255

256-
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
257-
// ...
256+
// src/DependencyInjection/AcmeSocialExtension.php
257+
namespace Acme\SocialBundle\DependencyInjection;
258258

259259
use Symfony\Component\Config\FileLocator;
260260
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -279,7 +279,7 @@ In your extension, you can load this and dynamically set its arguments::
279279
:class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\ConfigurableExtension`
280280
to do this automatically for you::
281281

282-
// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
282+
// src/DependencyInjection/HelloExtension.php
283283
namespace Acme\HelloBundle\DependencyInjection;
284284

285285
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -371,6 +371,7 @@ logic to the bundle class directly::
371371
configuration definition from one or more files::
372372

373373
// src/AcmeSocialBundle.php
374+
namespace Acme\SocialBundle;
374375

375376
// ...
376377
class AcmeSocialBundle extends AbstractBundle
@@ -413,7 +414,7 @@ The ``config:dump-reference`` command dumps the default configuration of a
413414
bundle in the console using the Yaml format.
414415

415416
As long as your bundle's configuration is located in the standard location
416-
(``YourBundle\DependencyInjection\Configuration``) and does not have
417+
(``<YourBundle>/src/DependencyInjection/Configuration``) and does not have
417418
a constructor, it will work automatically. If you
418419
have something different, your ``Extension`` class must override the
419420
:method:`Extension::getConfiguration() <Symfony\\Component\\DependencyInjection\\Extension\\Extension::getConfiguration>`
@@ -447,7 +448,8 @@ URL nor does it need to exist). By default, the namespace for a bundle is
447448
``http://example.org/schema/dic/DI_ALIAS``, where ``DI_ALIAS`` is the DI alias of
448449
the extension. You might want to change this to a more professional URL::
449450

450-
// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
451+
// src/DependencyInjection/AcmeHelloExtension.php
452+
namespace Acme\HelloBundle\DependencyInjection;
451453

452454
// ...
453455
class AcmeHelloExtension extends Extension
@@ -476,10 +478,11 @@ namespace is then replaced with the XSD validation base path returned from
476478
method. This namespace is then followed by the rest of the path from the base
477479
path to the file itself.
478480

479-
By convention, the XSD file lives in the ``Resources/config/schema/``, but you
481+
By convention, the XSD file lives in ``config/schema/`` directory, but you
480482
can place it anywhere you like. You should return this path as the base path::
481483

482-
// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
484+
// src/DependencyInjection/AcmeHelloExtension.php
485+
namespace Acme\HelloBundle\DependencyInjection;
483486

484487
// ...
485488
class AcmeHelloExtension extends Extension
@@ -488,7 +491,7 @@ can place it anywhere you like. You should return this path as the base path::
488491

489492
public function getXsdValidationBasePath(): string
490493
{
491-
return __DIR__.'/../Resources/config/schema';
494+
return __DIR__.'/../config/schema';
492495
}
493496
}
494497

bundles/extension.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ performance. Define the list of annotated classes to compile in the
169169

170170
$this->addAnnotatedClassesToCompile([
171171
// you can define the fully qualified class names...
172-
'App\\Controller\\DefaultController',
172+
'Acme\\BlogBundle\\Controller\\AuthorController',
173173
// ... but glob patterns are also supported:
174-
'**Bundle\\Controller\\',
174+
'Acme\\BlogBundle\\Form\\**',
175175

176176
// ...
177177
]);

templates.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,10 @@ may include their own Twig templates (in the ``Resources/views/`` directory of
14431443
each bundle). To avoid messing with your own templates, Symfony adds bundle
14441444
templates under an automatic namespace created after the bundle name.
14451445

1446-
For example, the templates of a bundle called ``AcmeFooBundle`` are available
1447-
under the ``AcmeFoo`` namespace. If this bundle includes the template
1448-
``<your-project>/vendor/acmefoo-bundle/Resources/views/user/profile.html.twig``,
1449-
you can refer to it as ``@AcmeFoo/user/profile.html.twig``.
1446+
For example, the templates of a bundle called ``AcmeBlogBundle`` are available
1447+
under the ``AcmeBlog`` namespace. If this bundle includes the template
1448+
``<your-project>/vendor/acme/blog-bundle/Resources/views/user/profile.html.twig``,
1449+
you can refer to it as ``@AcmeBlog/user/profile.html.twig``.
14501450

14511451
.. tip::
14521452

0 commit comments

Comments
 (0)