Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cb3445

Browse files
committed
feature #32937 [Routing] Deprecate RouteCollectionBuilder (vudaltsov)
This PR was squashed before being merged into the 5.1-dev branch (closes #32937). Discussion ---------- [Routing] Deprecate RouteCollectionBuilder | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #32240 | License | MIT | Doc PR | symfony/symfony-docs#12688 | Recipe PR | symfony/recipes#690 A lot to be done here after the implementation is accepted: - [x] finish deprecations in the MicroKernelTrait - [x] deprecate the class - [x] mention in the CHANGELOG file - [x] mention in the UPGRADE file - [x] mark tests as legacy - [x] add a doc PR - [x] update the recipe Ping @Tobion , @nicolas-grekas . Commits ------- e641cbdd46 [Routing] Deprecate RouteCollectionBuilder
2 parents 3321782 + 04f0d0b commit 1cb3445

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.1.0
5+
-----
6+
7+
* Deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`.
8+
* Added support for a generic loader to `RoutingConfigurator`.
9+
410
5.0.0
511
-----
612

Loader/Configurator/RoutingConfigurator.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Routing\Loader\Configurator;
1313

14-
use Symfony\Component\Routing\Loader\PhpFileLoader;
14+
use Symfony\Component\Config\Exception\LoaderLoadException;
15+
use Symfony\Component\Config\Loader\FileLoader;
16+
use Symfony\Component\Config\Loader\LoaderInterface;
1517
use Symfony\Component\Routing\RouteCollection;
1618

1719
/**
@@ -25,7 +27,7 @@ class RoutingConfigurator
2527
private $path;
2628
private $file;
2729

28-
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file)
30+
public function __construct(RouteCollection $collection, LoaderInterface $loader, ?string $path, string $file)
2931
{
3032
$this->collection = $collection;
3133
$this->loader = $loader;
@@ -38,9 +40,7 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
3840
*/
3941
final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
4042
{
41-
$this->loader->setCurrentDir(\dirname($this->path));
42-
43-
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude) ?: [];
43+
$imported = $this->load($resource, $type, $ignoreErrors, $exclude) ?: [];
4444
if (!\is_array($imported)) {
4545
return new ImportConfigurator($this->collection, $imported);
4646
}
@@ -57,4 +57,34 @@ final public function collection(string $name = ''): CollectionConfigurator
5757
{
5858
return new CollectionConfigurator($this->collection, $name);
5959
}
60+
61+
/**
62+
* @param string|string[]|null $exclude
63+
*
64+
* @return RouteCollection|RouteCollection[]|null
65+
*/
66+
private function load($resource, ?string $type, bool $ignoreErrors, $exclude)
67+
{
68+
$loader = $this->loader;
69+
70+
if (!$loader->supports($resource, $type)) {
71+
if (null === $resolver = $loader->getResolver()) {
72+
throw new LoaderLoadException($resource, $this->file, null, null, $type);
73+
}
74+
75+
if (false === $loader = $resolver->resolve($resource, $type)) {
76+
throw new LoaderLoadException($resource, $this->file, null, null, $type);
77+
}
78+
}
79+
80+
if (!$loader instanceof FileLoader) {
81+
return $loader->load($resource, $type);
82+
}
83+
84+
if (null !== $this->path) {
85+
$this->loader->setCurrentDir(\dirname($this->path));
86+
}
87+
88+
return $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude);
89+
}
6090
}

RouteCollectionBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Helps add and import routes into a RouteCollection.
2020
*
2121
* @author Ryan Weaver <[email protected]>
22+
*
23+
* @deprecated since Symfony 5.1, use RoutingConfigurator instead
2224
*/
2325
class RouteCollectionBuilder
2426
{

Tests/RouteCollectionBuilderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Symfony\Component\Routing\RouteCollection;
2020
use Symfony\Component\Routing\RouteCollectionBuilder;
2121

22+
/**
23+
* @group legacy
24+
*/
2225
class RouteCollectionBuilderTest extends TestCase
2326
{
2427
public function testImport()

0 commit comments

Comments
 (0)