@@ -177,6 +177,49 @@ You can begin specifying configuration under this namespace immediately:
177
177
array. You can still provide some sensible defaults for your bundle if
178
178
you want.
179
179
180
+ Registering the Extension class
181
+ -------------------------------
182
+
183
+ An Extension class will automatically be registered by Symfony2 when following these simple conventions:
184
+
185
+ * The extension must be stored in the ``DependencyInjection `` sub-namespace;
186
+
187
+ * The extension must be named after the bundle name and suffixed with
188
+ ``Extension `` (``AcmeHelloExtension `` for ``AcmeHelloBundle ``);
189
+
190
+ * The extension should provide an XSD schema.
191
+
192
+ Manually registering an Extension class
193
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194
+
195
+ To manually register an extension class override the
196
+ :method: `Bundle::build() <Symfony\\ Component\\ HttpKernel\\ Bundle\\ Bundle::build> `
197
+ method in your bundle::
198
+
199
+ // ...
200
+ use Acme\HelloBundle\DependencyInjection\UnconventionalExtensionClass;
201
+
202
+ class AcmeHelloBundle extends Bundle
203
+ {
204
+ public function build(ContainerBuilder $container)
205
+ {
206
+ parent::build($container);
207
+
208
+ // register extensions that do not follow the conventions manually
209
+ $container->registerExtension(new UnconventionalExtensionClass());
210
+ }
211
+ }
212
+
213
+ In this case, the extension class must also implement a ``getAlias() `` method
214
+ and return a unique alias named after the bundle (e.g. ``acme_hello ``). This
215
+ is required because the class name doesn't follow the conventions by ending
216
+ in ``Extension ``.
217
+
218
+ Additionally, the ``load() `` method of your extension will *only * be called
219
+ if the user specifies the ``acme_hello `` alias in at least one configuration
220
+ file. Once again, this is because the Extension class doesn't follow the
221
+ conventions set out above, so nothing happens automatically.
222
+
180
223
Parsing the ``$configs `` Array
181
224
------------------------------
182
225
@@ -511,9 +554,6 @@ For more details, see :doc:`/cookbook/bundles/prepend_extension`.
511
554
Default Configuration Dump
512
555
~~~~~~~~~~~~~~~~~~~~~~~~~~
513
556
514
- .. versionadded :: 2.1
515
- The ``config:dump-reference `` command was added in Symfony 2.1
516
-
517
557
The ``config:dump-reference `` command allows a bundle's default configuration to
518
558
be output to the console in YAML.
519
559
@@ -561,46 +601,5 @@ command.
561
601
.. index ::
562
602
pair: Convention; Configuration
563
603
564
- Extension Conventions
565
- ---------------------
566
-
567
- When creating an extension, follow these simple conventions:
568
-
569
- * The extension must be stored in the ``DependencyInjection `` sub-namespace;
570
-
571
- * The extension must be named after the bundle name and suffixed with
572
- ``Extension `` (``AcmeHelloExtension `` for ``AcmeHelloBundle ``);
573
-
574
- * The extension should provide an XSD schema.
575
-
576
- If you follow these simple conventions, your extensions will be registered
577
- automatically by Symfony2. If not, override the
578
- :method: `Bundle::build() <Symfony\\ Component\\ HttpKernel\\ Bundle\\ Bundle::build> `
579
- method in your bundle::
580
-
581
- // ...
582
- use Acme\HelloBundle\DependencyInjection\UnconventionalExtensionClass;
583
-
584
- class AcmeHelloBundle extends Bundle
585
- {
586
- public function build(ContainerBuilder $container)
587
- {
588
- parent::build($container);
589
-
590
- // register extensions that do not follow the conventions manually
591
- $container->registerExtension(new UnconventionalExtensionClass());
592
- }
593
- }
594
-
595
- In this case, the extension class must also implement a ``getAlias() `` method
596
- and return a unique alias named after the bundle (e.g. ``acme_hello ``). This
597
- is required because the class name doesn't follow the standards by ending
598
- in ``Extension ``.
599
-
600
- Additionally, the ``load() `` method of your extension will *only * be called
601
- if the user specifies the ``acme_hello `` alias in at least one configuration
602
- file. Once again, this is because the Extension class doesn't follow the
603
- standards set out above, so nothing happens automatically.
604
-
605
604
.. _`FrameworkBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
606
605
.. _`TwigBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
0 commit comments