Skip to content

Commit 4518784

Browse files
committed
[DependencyInjection][Routing] Access environment in PHP config
1 parent 63abf57 commit 4518784

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ CHANGELOG
55
---
66

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

1112
5.2.0
1213
-----

Loader/Configurator/RoutingConfigurator.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,11 @@ final public function collection(string $name = ''): CollectionConfigurator
6161
}
6262

6363
/**
64-
* @return static
64+
* Get the current environment to be able to write conditional configuration.
6565
*/
66-
final public function when(string $env): self
66+
final public function env(): ?string
6767
{
68-
if ($env === $this->env) {
69-
return clone $this;
70-
}
71-
72-
$clone = clone $this;
73-
$clone->collection = new RouteCollection();
74-
75-
return $clone;
68+
return $this->env;
7669
}
7770

7871
/**

Tests/Fixtures/when-env.php

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

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,4 @@ public function testImportingRoutesWithSingleHostInImporter()
284284

285285
$this->assertEquals($expectedRoutes('php'), $routes);
286286
}
287-
288-
public function testWhenEnv()
289-
{
290-
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']), 'some-env');
291-
$routes = $loader->load('when-env.php');
292-
293-
$this->assertSame(['b', 'a'], array_keys($routes->all()));
294-
$this->assertSame('/b', $routes->get('b')->getPath());
295-
$this->assertSame('/a1', $routes->get('a')->getPath());
296-
}
297287
}

0 commit comments

Comments
 (0)