Skip to content

Commit 28c144a

Browse files
committed
plug xml and php version of the configuration
1 parent c07c655 commit 28c144a

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

cookbook/configuration/using_configuration_parameters.rst

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ If for instance, there is a use case in which you want to use the
6868
``%kernel.debug%`` debug mode parameter to make your bundle adapt its
6969
configuration depending on this. For this case you cannot use
7070
the syntax directly and expect this to work. The configuration handling
71-
will just tread this ``%kernel.debug%`` as a string. Consider
71+
will just treat this ``%kernel.debug%`` as a string. Consider
7272
this example with the AcmeDemoBundle::
7373

7474
// Inside Configuration class
75-
->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
75+
$rootNode
76+
->children()
77+
->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
78+
// ...
79+
->end()
80+
;
7681

7782
// Inside the Extension class
7883
$config = $this->processConfiguration($configuration, $configs);
@@ -102,11 +107,46 @@ Now, examine the results to see this closely:
102107
103108
.. code-block:: xml
104109
105-
I confess i need help here @WouterJ
110+
<?xml version="1.0" encoding="UTF-8" ?>
111+
<container xmlns="http://symfony.com/schema/dic/services"
112+
my-bundle="http://example.org/schema/dic/my_bundle">
113+
114+
<my-bundle:config logging="true" />
115+
<!-- true, as expected -->
116+
117+
<my-bundle:config logging="%kernel.debug%" />
118+
<!-- true/false (depends on 2nd parameter of AppKernel),
119+
as expected, because %kernel.debug% inside configuration
120+
gets evaluated before being passed to the extension -->
121+
122+
<my-bundle:config />
123+
<!-- passes the string "%kernel.debug%".
124+
Which is always considered as true.
125+
The Configurator does not know anything about
126+
"%kernel.debug%" being a parameter. -->
127+
</container>
106128
107129
.. code-block:: php
108130
109-
I confess i need help here @WouterJ
131+
$container->loadFromExtension('my_bundle', array(
132+
'logging' => true,
133+
// true, as expected
134+
)
135+
);
136+
137+
$container->loadFromExtension('my_bundle', array(
138+
'logging' => "%kernel.debug%",
139+
// true/false (depends on 2nd parameter of AppKernel),
140+
// as expected, because %kernel.debug% inside configuration
141+
// gets evaluated before being passed to the extension
142+
)
143+
);
144+
145+
$container->loadFromExtension('my_bundle');
146+
// passes the string "%kernel.debug%".
147+
// Which is always considered as true.
148+
// The Configurator does not know anything about
149+
// "%kernel.debug%" being a parameter.
110150
111151
In order to support this use case, the ``Configuration`` class has to
112152
be injected with this parameter via the extension as follows::

0 commit comments

Comments
 (0)