symfony: [DI] Unable to resolve env()
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.2.2 |
Hi,
I’m trying to use the new env()
placeholder introduced with https://github.com/symfony/symfony/pull/19681, but I can’t get it to work. I installed symfony/dependency-injection|config|yaml
, and I followed Setting up the Container with Configuration Files.
This is my script—mostly copy/pasted from the documentation:
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.yml');
var_dump(getenv('NAME'));
var_dump($container->getParameter('test'));
This is my services.yml
file:
parameters:
test: '%env(NAME)%'
And this is the output of the command NAME=madonna php test.php
:
/Volumes/GIT/olvlvl/test-di-env/test.php:13:
string(7) "madonna"
/Volumes/GIT/olvlvl/test-di-env/test.php:14:
string(11) "%env(NAME)%"
I also read How to Set external Parameters in the Service Container but it doesn’t give more information, so I’m not sure what’s wrong.
Here is the package list:
symfony/config v3.2.2 Symfony Config Component
symfony/dependency-injection v3.2.2 Symfony DependencyInjection Component
symfony/filesystem v3.2.2 Symfony Filesystem Component
symfony/yaml v3.2.2 Symfony Yaml Component
Can you help?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (20 by maintainers)
Commits related to this issue
- feature #21460 [DI] ContainerBuilder::compile() can optionally resolve env vars in parameter bag (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] ContainerBui... — committed to symfony/symfony by fabpot 7 years ago
- compile and resolve env vars see https://github.com/symfony/symfony/issues/21420 — committed to nagibyro/hal-core by deleted user 7 years ago
And does it work also when using #21460 - then doing
$container->compile(true)
?@olvlvl Here is what you need: