5
5
How to simplify configuration of multiple Bundle
6
6
================================================
7
7
8
- Especially when building reusable and extensible applications developers are
9
- often faced with a choice, either create a single Bundle or create multiple
10
- Bundles. Creating a single Bundle has the draw back that its impossible for
8
+ When building reusable and extensible applications, developers are often
9
+ faced with a choice: either create a single large Bundle or multiple smaller
10
+ Bundles. Creating a single Bundle has the draw back that it's impossible for
11
11
users to choose to remove functionality they are not using. Creating multiple
12
12
Bundles has the draw back that configuration becomes more tedious and settings
13
13
often need to be repeated for various Bundles.
14
14
15
- Using the below approach it is possible to remove the disadvantage of the
16
- multiple Bundle approach, by enabling a single Extension to prepend the settings
15
+ Using the below approach, it is possible to remove the disadvantage of the
16
+ multiple Bundle approach by enabling a single Extension to prepend the settings
17
17
for any Bundle. It can use the settings defined in the ``app/config/config.yml ``
18
18
to prepend settings just as if they would have been written explicitly by the
19
19
user in the application configuration.
20
20
21
21
For example, this could be used to configure the entity manager name to use in
22
- multiple Bundle . Or it can be used to enable an optional feature that depends
22
+ multiple Bundles . Or it can be used to enable an optional feature that depends
23
23
on another Bundle being loaded as well.
24
24
25
- In order for an Extension to be able to do this it needs to implement
25
+ To give an Extension the power to do this, it needs to implement
26
26
:class: `Symfony\\ Component\\ DependencyInjection\\ Compiler\\ PrependExtensionInterface `::
27
27
28
28
// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
@@ -42,19 +42,19 @@ In order for an Extension to be able to do this it needs to implement
42
42
}
43
43
}
44
44
45
- Inside the :method: `Symfony\\ Component\\ DependencyInjection\\ Compiler\\ PrependExtensionInterface::prepend() `
46
- method developers have full access to the :class: `Symfony\C omponent\D ependencyInjection\C ontainerBuilder `
47
- instance just before the :method: `Symfony\C omponent\H ttpKernel \D ependencyInjection\E xtensionInterface:load() `
48
- method is called on the registered Bundle Extensions. In order to prepend settings
49
- to a Bundle extension developers can use the
50
- :method: `Symfony\C omponent\D ependencyInjection\C ontainerBuilder:prependExtensionConfig() `
51
- method on the :class: `Symfony\C omponent\D ependencyInjection\C ontainerBuilder `
45
+ Inside the :method: `Symfony\\ Component\\ DependencyInjection\\ Compiler\\ PrependExtensionInterface::prepend `
46
+ method, developers have full access to the :class: `Symfony\\ Component\\ DependencyInjection\ \ ContainerBuilder `
47
+ instance just before the :method: `Symfony\\ Component\\ DependencyInjection\\ Extension \\ ExtensionInterface:: load `
48
+ method is called on each of the registered Bundle Extensions. In order to
49
+ prepend settings to a Bundle extension developers can use the
50
+ :method: `Symfony\\ Component\\ DependencyInjection\\ ContainerBuilder:: prependExtensionConfig `
51
+ method on the :class: `Symfony\\ Component\\ DependencyInjection\ \ ContainerBuilder `
52
52
instance. As this method only prepends settings, any other settings done explicitly
53
53
inside the ``app/config/config.yml `` would override these prepended settings.
54
54
55
55
The following example illustrates how to prepend
56
56
a configuration setting in multiple Bundles as well as disable a flag in multiple Bundles
57
- in case specific other Bundle is not registered::
57
+ in case a specific other Bundle is not registered::
58
58
59
59
public function prepend(ContainerBuilder $container)
60
60
{
@@ -92,7 +92,7 @@ in case specific other Bundle is not registered::
92
92
93
93
The above would be the equivalent of writing the following into the ``app/config/config.yml ``
94
94
in case ``AcmeGoodbyeBundle `` is not registered and the ``entity_manager_name `` setting
95
- for ``acme_hello `` is set to ``non_default ``::
95
+ for ``acme_hello `` is set to ``non_default ``:
96
96
97
97
.. configuration-block ::
98
98
0 commit comments