1111
1212namespace 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 ;
1517use 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}
0 commit comments