8000 [Cookbook][Configuration] add configuration cookbook handlig parameters in Configurator class by cordoval · Pull Request #3420 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Cookbook][Configuration] add configuration cookbook handlig parameters in Configurator class #3420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plug xml and php version of the configuration
  • Loading branch information
cordoval committed Jan 6, 2014
commit 28c144a4f4d6d67956a37aca401a905ed0917563
48 changes: 44 additions & 4 deletions cookbook/configuration/using_configuration_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ If for instance, there is a use case in which you want to use the
``%kernel.debug%`` debug mode parameter to make your bundle adapt its
configuration depending on this. For this case you cannot use
the syntax directly and expect this to work. The configuration handling
will just tread this ``%kernel.debug%`` as a string. Consider
will just treat this ``%kernel.debug%`` as a string. Consider
this example with the AcmeDemoBundle::

// Inside Configuration class
->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
$rootNode
->children()
->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
// ...
->end()
;

// Inside the Extension class
$config = $this->processConfiguration($configuration, $configs);
Expand Down Expand Up @@ -102,11 +107,46 @@ Now, examine the results to see this closely:

.. code-block:: xml

I confess i need help here @WouterJ
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
my-bundle="http://example.org/schema/dic/my_bundle">

<my-bundle:config logging="true" />
<!-- true, as expected -->

<my-bundle:config logging="%kernel.debug%" />
<!-- true/false (depends on 2nd parameter of AppKernel),
as expected, because %kernel.debug% inside configuration
gets evaluated before being passed to the extension -->

<my-bundle:config />
<!-- passes the string "%kernel.debug%".
Which is always considered as true.
The Configurator does not know anything about
"%kernel.debug%" being a parameter. -->
</container>

.. code-block:: php

I confess i need help here @WouterJ
$container->loadFromExtension('my_bundle', array(
'logging' => true,
// true, as expected
)
);

$container->loadFromExtension('my_bundle', array(
'logging' => "%kernel.debug%",
// true/false (depends on 2nd parameter of AppKernel),
// as expected, because %kernel.debug% inside configuration
// gets evaluated before being passed to the extension
)
);

$container->loadFromExtension('my_bundle');
// passes the string "%kernel.debug%".
// Which is always considered as true.
// The Configurator does not know anything about
// "%kernel.debug%" being a parameter.

In order to support this use case, the ``Configuration`` class has to
be injected with this parameter via the extension as follows::
Expand Down
0