Skip to content

[DI] resolve: env processor can override real envs #44756

@ro0NL

Description

@ro0NL

Description

See https://github.com/ro0NL/sf-env (6.1)

An issue occurs when using %env(resolve:ENV)%, when ENV contains a nested %env(INNER)%. The nested env is loaded from parameters, not real envs.

So given

TEST_ENV_INNER='im defined in .env'
TEST_ENV="pre [%env(TEST_ENV_INNER)%] post"
parameters:
    env(TEST_ENV_INNER): 'im defined in services.yaml'

services:
    _defaults:
        bind:
            'string $testEnvValue': '%env(resolve:TEST_ENV)%'

Then running

$ bin/console test
^ "pre [im defined in services.yaml] post"

Expected is pre [im defined in .env] post

Now running TEST_ENV_INNER=real bin/console test produces the same output, whereas pre [real] post is expected

We found a hackish workaround using env(INNER): '%env(INNER)%', but this should probably happen out-of-the-box ... as this is a circular reference IMHO.

cc @nicolas-grekas

Example

No response

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