8000 [DI] Unable to resolve env() · Issue #21420 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[DI] Unable to resolve env() #21420
Closed
Closed
@olvlvl

Description

@olvlvl
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 #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?

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

      0