diff --git a/src/ServiceContainer/DefaultLoaderFactory.php b/src/ServiceContainer/DefaultLoaderFactory.php new file mode 100644 index 0000000..8652f5d --- /dev/null +++ b/src/ServiceContainer/DefaultLoaderFactory.php @@ -0,0 +1,40 @@ + + */ +final class DefaultLoaderFactory implements LoaderFactory +{ + /** + * {@inheritdoc} + */ + public function createLoader(ContainerBuilder $container, array $config) + { + $fileLocator = new FileLocator($container->getParameter('paths.base')); + + return new DelegatingLoader(new LoaderResolver([ + new XmlFileLoader($container, $fileLocator), + new YamlFileLoader($container, $fileLocator), + new PhpFileLoader($container, $fileLocator), + ])); + } +} diff --git a/src/ServiceContainer/LoaderFactory.php b/src/ServiceContainer/LoaderFactory.php new file mode 100644 index 0000000..68bb69c --- /dev/null +++ b/src/ServiceContainer/LoaderFactory.php @@ -0,0 +1,29 @@ + + */ +interface LoaderFactory +{ + /** + * @param ContainerBuilder $container + * @param array $config + * + * @return LoaderInterface + */ + public function createLoader(ContainerBuilder $container, array $config); +} diff --git a/src/ServiceContainer/ServiceContainerExtension.php b/src/ServiceContainer/ServiceContainerExtension.php index 7096b65..3dbd363 100644 --- a/src/ServiceContainer/ServiceContainerExtension.php +++ b/src/ServiceContainer/ServiceContainerExtension.php @@ -16,6 +16,7 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; @@ -28,6 +29,28 @@ final class ServiceContainerExtension implements Extension { /** + * @var LoaderFactory + */ + private $loaderFactory; + + public function __construct() + { + $this->loaderFactory = new DefaultLoaderFactory(); + } + + /** + * @api + * + * @param LoaderFactory $loaderFactory + */ + public function setLoaderCallable(LoaderFactory $loaderFactory) + { + $this->loaderFactory = $loaderFactory; + } + + /** + * @internal + * * {@inheritdoc} */ public function getConfigKey() @@ -36,6 +59,8 @@ public function getConfigKey() } /** + * @internal + * * {@inheritdoc} */ public function initialize(ExtensionManager $extensionManager) @@ -44,6 +69,8 @@ public function initialize(ExtensionManager $extensionManager) } /** + * @internal + * * {@inheritdoc} */ public function configure(ArrayNodeDefinition $builder) @@ -57,17 +84,13 @@ public function configure(ArrayNodeDefinition $builder) } /** + * @internal + * * {@inheritdoc} */ public function load(ContainerBuilder $container, array $config) { - $fileLocator = new FileLocator($container->getParameter('paths.base')); - - $loader = new DelegatingLoader(new LoaderResolver([ - new XmlFileLoader($container, $fileLocator), - new YamlFileLoader($container, $fileLocator), - new PhpFileLoader($container, $fileLocator), - ])); + $loader = $this->loaderFactory->createLoader($container, $config); foreach ($config['imports'] as $file) { $loader->load($file); @@ -75,6 +98,8 @@ public function load(ContainerBuilder $container, array $config) } /** + * @internal + * * {@inheritdoc} */ public function process(ContainerBuilder $container)