Skip to content

Dynamic parameter does not work in static parameter #291

@ondrejmirtes

Description

@ondrejmirtes

Version: 3.1.2

Bug Description

The documentation says (https://doc.nette.org/en/application/bootstrap#toc-dynamic-parameters):

We can also add dynamic parameters to the container, their different values, unlike static parameters, will not cause the generation of new DI containers. Environment variables could be easily made available using dynamic parameters. We can access them via %env.variable% in configuration files.

When I try this in practice, the parameter value is null instead of the expected value of expanded env variable.

Steps To Reproduce

I created a minimal project that shows this problem: https://github.com/ondrejmirtes/nette-di-dynamic

The script test.php:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$configurator = new Nette\Bootstrap\Configurator;
$configurator->setTempDirectory(__DIR__ . '/temp');
$configurator->addConfig(__DIR__ . '/test.neon');
$configurator->addDynamicParameters([
	'env' => getenv(),
]);
$container = $configurator->createContainer();

var_dump($container->parameters['test']);

The neon file test.neon:

parameters:
	test: %env.NETTE_TEST%/foo

How to run:

export NETTE_TEST=foo
php test.php

Expected Behavior

string(7) "foo/foo"

Actual Behaviour

NULL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions