@@ -22,12 +22,15 @@ file::
22
22
return [
23
23
// 'all' means that the bundle is enabled for any Symfony environment
24
24
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
+
29
31
// this bundle is enabled only in 'dev' and 'test', so you can't use it in 'prod'
30
32
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
33
+ // ...
31
34
];
32
35
33
36
.. tip ::
@@ -40,18 +43,18 @@ Creating a Bundle
40
43
-----------------
41
44
42
45
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
44
47
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 ``).
46
49
47
- Start by creating a new class called ``AcmeTestBundle ``::
50
+ Start by creating a new class called ``AcmeBlogBundle ``::
48
51
49
- // src/AcmeTestBundle .php
50
- namespace Acme\TestBundle ;
52
+ // src/AcmeBlogBundle .php
53
+ namespace Acme\BlogBundle ;
51
54
52
55
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
53
56
54
- class AcmeTestBundle extends AbstractBundle
57
+ class AcmeBlogBundle extends AbstractBundle
55
58
{
56
59
}
57
60
@@ -67,10 +70,10 @@ Start by creating a new class called ``AcmeTestBundle``::
67
70
68
71
.. tip ::
69
72
70
- The name AcmeTestBundle follows the standard
73
+ The name AcmeBlogBundle follows the standard
71
74
:ref: `Bundle naming conventions <bundles-naming-conventions >`. You could
72
- also choose to shorten the name of the bundle to simply TestBundle by naming
73
- this class TestBundle (and naming the file ``TestBundle .php ``).
75
+ also choose to shorten the name of the bundle to simply BlogBundle by naming
76
+ this class BlogBundle (and naming the file ``BlogBundle .php ``).
74
77
75
78
This empty class is the only piece you need to create the new bundle. Though
76
79
commonly empty, this class is powerful and can be used to customize the behavior
@@ -79,10 +82,10 @@ of the bundle. Now that you've created the bundle, enable it::
79
82
// config/bundles.php
80
83
return [
81
84
// ...
82
- Acme\TestBundle\AcmeTestBundle ::class => ['all' => true],
85
+ Acme\BlogBundle\AcmeBlogBundle ::class => ['all' => true],
83
86
];
84
87
85
- And while it doesn't do anything yet, AcmeTestBundle is now ready to be used.
88
+ And while it doesn't do anything yet, AcmeBlogBundle is now ready to be used.
86
89
87
90
Bundle Directory Structure
88
91
--------------------------
@@ -91,31 +94,31 @@ The directory structure of a bundle is meant to help to keep code consistent
91
94
between all Symfony bundles. It follows a set of conventions, but is flexible
92
95
to be adjusted if needed:
93
96
94
- ``src/ ``
95
- Contains all PHP classes related to the bundle logic (e.g. ``Controller/RandomController.php ``).
97
+ ``assets/ ``
98
+ Contains the web asset sources like JavaScript and TypeScript files, CSS and
99
+ Sass files, but also images and other assets related to the bundle that are
100
+ not in ``public/ `` (e.g. Stimulus controllers).
96
101
97
102
``config/ ``
98
- Houses configuration, including routing configuration (e.g. ``routing.yaml ``).
99
-
100
- ``templates/ ``
101
- Holds templates organized by controller name (e.g. ``random/index.html.twig ``).
102
-
103
- ``translations/ ``
104
- Holds translations organized by domain and locale (e.g. ``AcmeTestBundle.en.xlf ``).
103
+ Houses configuration, including routing configuration (e.g. ``routes.php ``).
105
104
106
105
``public/ ``
107
106
Contains web assets (images, compiled CSS and JavaScript files, etc.) and is
108
107
copied or symbolically linked into the project ``public/ `` directory via the
109
108
``assets:install `` console command.
110
109
111
- ``assets/ ``
112
- Contains the web asset sources (JavaScript and TypeScript files, CSS and Sass
113
- files, etc.), images and other assets related to the bundle that are not in
114
- ``public/ `` (e.g. Stimulus controllers)
110
+ ``src/ ``
111
+ Contains all PHP classes related to the bundle logic (e.g. ``Controller/CategoryController.php ``).
112
+
113
+ ``templates/ ``
114
+ Holds templates organized by controller name (e.g. ``category/show.html.twig ``).
115
115
116
116
``tests/ ``
117
117
Holds all tests for the bundle.
118
118
119
+ ``translations/ ``
120
+ Holds translations organized by domain and locale (e.g. ``AcmeBlogBundle.en.xlf ``).
121
+
119
122
.. caution ::
120
123
121
124
The recommended bundle structure was changed in Symfony 5, read the
@@ -126,7 +129,7 @@ to be adjusted if needed:
126
129
new structure. Override the ``Bundle::getPath() `` method to change to
127
130
the old structure::
128
131
129
- class AcmeTestBundle extends AbstractBundle
132
+ class AcmeBlogBundle extends AbstractBundle
130
133
{
131
134
public function getPath(): string
132
135
{
@@ -145,12 +148,12 @@ to be adjusted if needed:
145
148
{
146
149
"autoload" : {
147
150
"psr-4" : {
148
- "Acme\\ TestBundle \\ " : " src/"
151
+ "Acme\\ BlogBundle \\ " : " src/"
149
152
}
150
153
},
151
154
"autoload-dev" : {
152
155
"psr-4" : {
153
- "Acme\\ TestBundle \\ Tests\\ " : " tests/"
156
+ "Acme\\ BlogBundle \\ Tests\\ " : " tests/"
154
157
}
155
158
}
156
159
}
0 commit comments