11
11
12
12
namespace Symfony \Component \Routing \Loader \Configurator ;
13
13
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 ;
15
17
use Symfony \Component \Routing \RouteCollection ;
16
18
17
19
/**
@@ -25,7 +27,7 @@ class RoutingConfigurator
25
27
private $ path ;
26
28
private $ file ;
27
29
28
- public function __construct (RouteCollection $ collection , PhpFileLoader $ loader , string $ path , string $ file )
30
+ public function __construct (RouteCollection $ collection , LoaderInterface $ loader , ? string $ path , string $ file )
29
31
{
30
32
$ this ->collection = $ collection ;
31
33
$ this ->loader = $ loader ;
@@ -38,9 +40,7 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
38
40
*/
39
41
final public function import ($ resource , string $ type = null , bool $ ignoreErrors = false , $ exclude = null ): ImportConfigurator
40
42
{
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 ) ?: [];
44
44
if (!\is_array ($ imported )) {
45
45
return new ImportConfigurator ($ this ->collection , $ imported );
46
46
}
@@ -57,4 +57,34 @@ final public function collection(string $name = ''): CollectionConfigurator
57
57
{
58
58
return new CollectionConfigurator ($ this ->collection , $ name );
59
59
}
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
+ }
60
90
}
0 commit comments