Skip to content

[DependencyInjection][Routing] Access environment in PHP config #40808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ CHANGELOG
* Add `#[AsTaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
* Add autoconfigurable attributes
* Add support for autowiring tagged iterators and locators via attributes on PHP 8
* Add support for per-env configuration in loaders
* Add support for per-env configuration in XML and Yaml loaders
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
* Add support an integer return value for default_index_method
* Add `env()` and `EnvConfigurator` in the PHP-DSL
* Add support for `ConfigBuilder` in the `PhpFileLoader`
* Add `ContainerConfigurator::env()` to get the current environment

5.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,11 @@ final public function services(): ServicesConfigurator
}

/**
* @return static
* Get the current environment to be able to write conditional configuration.
*/
final public function when(string $env): self
final public function env(): ?string
{
if ($env === $this->env) {
return clone $this;
}

$instanceof = $this->instanceof;
$clone = clone $this;
$clone->container = new ContainerBuilder(clone $this->container->getParameterBag());
$clone->instanceof = &$instanceof;

return $clone;
return $this->env;
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ public function testStack()
$this->assertEquals($expected, $container->get('stack_d'));
}

public function testWhenEnv()
{
$container = new ContainerBuilder();
$loader = new PhpFileLoader($container, new FileLocator(realpath(__DIR__.'/../Fixtures').'/config'), 'some-env');
$loader->load('when-env.php');

$this->assertSame(['foo' => 234, 'bar' => 345], $container->getParameterBag()->all());
}

public function testEnvConfigurator()
{
$container = new ContainerBuilder();
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ CHANGELOG
---

* Already encoded slashes are not decoded nor double-encoded anymore when generating URLs
* Add support for per-env configuration in loaders
* Add support for per-env configuration in XML and Yaml loaders
* Deprecate creating instances of the `Route` annotation class by passing an array of parameters
* Add `RoutingConfigurator::env()` to get the current environment

5.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,11 @@ final public function collection(string $name = ''): CollectionConfigurator
}

/**
* @return static
* Get the current environment to be able to write conditional configuration.
*/
final public function when(string $env): self
final public function env(): ?string
{
if ($env === $this->env) {
return clone $this;
}

$clone = clone $this;
$clone->collection = new RouteCollection();

return $clone;
return $this->env;
}

/**
Expand Down
18 changes: 0 additions & 18 deletions src/Symfony/Component/Routing/Tests/Fixtures/when-env.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,4 @@ public function testImportingRoutesWithSingleHostInImporter()

$this->assertEquals($expectedRoutes('php'), $routes);
}

public function testWhenEnv()
{
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']), 'some-env');
$routes = $loader->load('when-env.php');

$this->assertSame(['b', 'a'], array_keys($routes->all()));
$this->assertSame('/b', $routes->get('b')->getPath());
$this->assertSame('/a1', $routes->get('a')->getPath());
}
}