Skip to content

[DI], [Config] - Environment variables can not be used with configuration nodes of concrete types #25868

Closed
@edefimov

Description

@edefimov
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.3

Suppose we have defined such configuration in Configuration.php:

public function getConfigTreeBuilder()
{
    $tree = new TreeBuilder();
    $root = $tree->root('my_bundle');
    $root
        ->children()
            ->floatNode('float_value')->end()
        ->end();
    return $tree;
}

Next we want to use environment variable for this configuration, as described here:

my_bundle:
  float_value: "%env(float:MY_VALUE)%"

After that we add MY_VALUE into .env file and try to run

php bin/console cache:clear

The execution result will be an error:

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!  
!!  In FloatNode.php line 34:
!!                                                                                 
!!    Invalid type for path "my_bundle.float_value"  
!!    Expected float, but got string.                                   
!!                                                                              
!!  

The command should be executed successfully.

Repository with code to reproduce this situation. The steps:

composer install
bin/console list

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