1616use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
1717use Symfony \Component \Config \FileLocator ;
1818use Symfony \Component \Config \Loader \DelegatingLoader ;
19+ use Symfony \Component \Config \Loader \LoaderInterface ;
1920use Symfony \Component \Config \Loader \LoaderResolver ;
2021use Symfony \Component \DependencyInjection \ContainerBuilder ;
2122use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
2829final class ServiceContainerExtension implements Extension
2930{
3031 /**
32+ * @var callable<ContainerBuilder, array>:LoaderInterface
33+ */
34+ private $ loaderCallable ;
35+
36+ public function __construct ()
37+ {
38+ $ this ->loaderCallable = function (ContainerBuilder $ container , array $ config ) {
39+ $ fileLocator = new FileLocator ($ container ->getParameter ('paths.base ' ));
40+
41+ return new DelegatingLoader (new LoaderResolver ([
42+ new XmlFileLoader ($ container , $ fileLocator ),
43+ new YamlFileLoader ($ container , $ fileLocator ),
44+ new PhpFileLoader ($ container , $ fileLocator ),
45+ ]));
46+ };
47+ }
48+
49+ /**
50+ * @api
51+ *
52+ * @param callable<ContainerBuilder, array>:LoaderInterface $loaderCallable
53+ */
54+ public function setLoaderCallable (callable $ loaderCallable )
55+ {
56+ $ this ->loaderCallable = $ loaderCallable ;
57+ }
58+
59+ /**
60+ * @internal
61+ *
3162 * {@inheritdoc}
3263 */
3364 public function getConfigKey ()
@@ -36,6 +67,8 @@ public function getConfigKey()
3667 }
3768
3869 /**
70+ * @internal
71+ *
3972 * {@inheritdoc}
4073 */
4174 public function initialize (ExtensionManager $ extensionManager )
@@ -44,6 +77,8 @@ public function initialize(ExtensionManager $extensionManager)
4477 }
4578
4679 /**
80+ * @internal
81+ *
4782 * {@inheritdoc}
4883 */
4984 public function configure (ArrayNodeDefinition $ builder )
@@ -57,24 +92,25 @@ public function configure(ArrayNodeDefinition $builder)
5792 }
5893
5994 /**
95+ * @internal
96+ *
6097 * {@inheritdoc}
6198 */
6299 public function load (ContainerBuilder $ container , array $ config )
63100 {
64- $ fileLocator = new FileLocator ( $ container -> getParameter ( ' paths.base ' )) ;
101+ $ loaderCallable = $ this -> loaderCallable ;
65102
66- $ loader = new DelegatingLoader (new LoaderResolver ([
67- new XmlFileLoader ($ container , $ fileLocator ),
68- new YamlFileLoader ($ container , $ fileLocator ),
69- new PhpFileLoader ($ container , $ fileLocator ),
70- ]));
103+ /** @var LoaderInterface $loader */
104+ $ loader = $ loaderCallable ($ container , $ config );
71105
72106 foreach ($ config ['imports ' ] as $ file ) {
73107 $ loader ->load ($ file );
74108 }
75109 }
76110
77111 /**
112+ * @internal
113+ *
78114 * {@inheritdoc}
79115 */
80116 public function process (ContainerBuilder $ container )
0 commit comments