Skip to content

Can not read env()-parameter in a Compiler Pass #22456

@dbrumann

Description

@dbrumann
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions