Skip to content

Env variables don't pass the configuration #22594

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

Closed
theofidry opened this issue May 1, 2017 · 4 comments
Closed

Env variables don't pass the configuration #22594

theofidry opened this issue May 1, 2017 · 4 comments

Comments

@theofidry
Copy link
Contributor

theofidry commented May 1, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2.7

If you have a configuration node with a non-string type, e.g. IntegerNode, and pass an env variable, even though the env variable will be resolved in an integer, the value won't pass the validation and throw an error when booting.

e.g.:

parameters:
    int_val_param: '%env(INT_ENV_VAL)%'

app:
    int_val: '%int_val_param%'

or:

app:
    int_val: '%env(INT_ENV_VAL)%'

with:

// Configuration file

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();

    $treeBuilder->root('app')
        ->children()
            ->integerNode('int_val')
            ->isRequired()
            ->end()
        ->end()
    ;

    return $treeBuilder;
}

will throw:

  [Symfony\Component\DependencyInjection\Exception\EnvParameterException]
  Incompatible use of dynamic environment variables "INT_ENV_VAL" found in parameters.

  [Symfony\Component\Config\Definition\Exception\InvalidTypeException]
  Invalid type for path "app.int_val". Expected int, but got 'string'.

Issue reproduced on the repo: https://github.com/theofidry/symfony-22594

@ro0NL
Copy link
Contributor

ro0NL commented May 1, 2017

Related to #22151 i guess :)

@nicolas-grekas
Copy link
Member

Yep, that's the same topic. This is not a bug, the exception says it perfectly: this is just not supported yet.
Thus, this is a feature request. If one wants to work on typed env vars, please do.

@nicolas-grekas
Copy link
Member

Closing as duplicate.

@theofidry
Copy link
Contributor Author

theofidry commented May 1, 2017

Isn't it slightly different? #22151 is more about being able to cast the env value whereas here it's about allowing a string in the case of an env var for a non-string node. #22151 would be a way to fix this issue of course, but we could think of a simpler fix: don't throw a type exception when encountering an env variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants