Skip to content

Resolve environment variable on getConfigTreeBuilder #33358

Closed
@botjaeger

Description

@botjaeger

Hi, I'm trying to "determine" the value of my environment variable inside another symfony bundle

so in my main project I have this:

parameters.yml

bi_stream_enabled: '%env(BI_STREAM_ENABLED)%'

and config.yml

some_package:
    bi_stream:
        enabled: "%bi_stream_enabled%"

where BI_STREAM_ENABLED=true

then on another symfony bundle (package)

App\DependencyInjection\Configuration.php

$rootNode
            ->children()
                ->arrayNode('bi_stream')->addDefaultsIfNotSet()
                    ->children()
                        ->booleanNode('enabled')->isRequired()
                            ->beforeNormalization()
                                ->ifString()
                                    ->then(function($v) { dump($v); die; return in_array($v, ['true', 1, '1']) ? true : false; })
                            ->end()
                        ->defaultFalse()
                        ->end()
           ....

I always get false because I'm getting this value
env_BI_STREAM_ENABLED_25b06e350b1a33613de8efc12ddb1fe2

or this

env_bool_BI_STREAM_ENABLED_c1643fd79cbad73fa3172b243074fd04

if my parameter was set to this

bi_stream_enabled: '%env(bool:BI_STREAM_ENABLED)%'

I know, I can just change the code in my "some other package" but there are old "legacy" projects uses it.

is there a way to workaround this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions