Skip to content

Commit cef4169

Browse files
committed
[DependencyInjection][Routing] Access environment in PHP config
1 parent 6be36b9 commit cef4169

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ CHANGELOG
1010
* Add `#[AsTaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
1111
* Add autoconfigurable attributes
1212
* Add support for autowiring tagged iterators and locators via attributes on PHP 8
13-
* Add support for per-env configuration in loaders
13+
* Add support for per-env configuration in XML and Yaml loaders
1414
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
1515
* Add support an integer return value for default_index_method
1616
* Add `env()` and `EnvConfigurator` in the PHP-DSL
1717
* Add support for `ConfigBuilder` in the `PhpFileLoader`
18+
* Add `ContainerConfigurator::env()` to get the current environment
1819

1920
5.2.0
2021
-----

Loader/Configurator/ContainerConfigurator.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,11 @@ final public function services(): ServicesConfigurator
7474
}
7575

7676
/**
77-
* @return static
77+
* Get the current environment to be able to write conditional configuration.
7878
*/
79-
final public function when(string $env): self
79+
final public function env(): ?string
8080
{
81-
if ($env === $this->env) {
82-
return clone $this;
83-
}
84-
85-
$instanceof = $this->instanceof;
86-
$clone = clone $this;
87-
$clone->container = new ContainerBuilder(clone $this->container->getParameterBag());
88-
$clone->instanceof = &$instanceof;
89-
90-
return $clone;
81+
return $this->env;
9182
}
9283

9384
/**

Tests/Fixtures/config/when-env.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,6 @@ public function testStack()
144144
$this->assertEquals($expected, $container->get('stack_d'));
145145
}
146146

147-
public function testWhenEnv()
148-
{
149-
$container = new ContainerBuilder();
150-
$loader = new PhpFileLoader($container, new FileLocator(realpath(__DIR__.'/../Fixtures').'/config'), 'some-env');
151-
$loader->load('when-env.php');
152-
153-
$this->assertSame(['foo' => 234, 'bar' => 345], $container->getParameterBag()->all());
154-
}
155-
156147
public function testEnvConfigurator()
157148
{
158149
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)