-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.2.7 |
I encountered the following problem when writing a CompilerPass that reconfigures a services based on whether a certain parameter is checked. The CompilerPass looks something like this:
<?php
namespace AppBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class SomeCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->getParameter('env(SOME_PARAMETER)') == false) {
return;
}
if ($container->hasDefinition('app.some_service')) {
// TODO Interact with service
}
}
}
The parameter is set in my parameters.yml like this:
env(SOME_PARAMETER): false
Checking it after the Container is compiled (e.g. in a Controller) works fine, but in the Compiler Pass instead of the expected value false
getParameter will return something like: env_SOME_PARAMETER_d163dacb55d3a0dfb9e6236feba2ec26
.
I have also tried setting the environment variable with the same effect. The same condition using a "regular" parameter without env()
will return the expected value.