diff --git a/src/DependencyInjection/WebpackEncoreExtension.php b/src/DependencyInjection/WebpackEncoreExtension.php index 5a028e2..fa8fb53 100644 --- a/src/DependencyInjection/WebpackEncoreExtension.php +++ b/src/DependencyInjection/WebpackEncoreExtension.php @@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener; @@ -30,8 +30,8 @@ final class WebpackEncoreExtension extends Extension public function load(array $configs, ContainerBuilder $container): void { - $loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); - $loader->load('services.xml'); + $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); + $loader->load('services.php'); $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php new file mode 100644 index 0000000..5ead64e --- /dev/null +++ b/src/Resources/config/services.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + +use Symfony\Component\Cache\Adapter\PhpArrayAdapter; +use Symfony\Component\DependencyInjection\ServiceLocator; +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface; +use Symfony\WebpackEncoreBundle\Asset\TagRenderer; +use Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer; +use Symfony\WebpackEncoreBundle\EventListener\ExceptionListener; +use Symfony\WebpackEncoreBundle\EventListener\PreLoadAssetsEventListener; +use Symfony\WebpackEncoreBundle\EventListener\ResetAssetsEventListener; +use Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension; + +return static function (ContainerConfigurator $containerConfigurator): void { + $containerConfigurator->services() + ->set('webpack_encore.entrypoint_lookup_collection', EntrypointLookupCollection::class) + ->args([ + abstract_arg('build list of entrypoints locator'), + ]) + + ->alias(EntrypointLookupCollectionInterface::class, 'webpack_encore.entrypoint_lookup_collection') + + ->set('webpack_encore.tag_renderer', TagRenderer::class) + ->tag('kernel.reset', ['method' => 'reset']) + ->args([ + service('webpack_encore.entrypoint_lookup_collection'), + service('assets.packages'), + [], // Default attributes + [], // Default script attributes + [], // Default link attributes + service('event_dispatcher'), + ]) + + ->set('webpack_encore.twig_entry_files_extension', EntryFilesTwigExtension::class) + ->tag('twig.extension') + ->args([ + inline_service(ServiceLocator::class) + ->tag('container.service_locator') + ->args([ + [ + 'webpack_encore.entrypoint_lookup_collection' => service('webpack_encore.entrypoint_lookup_collection'), + 'webpack_encore.tag_renderer' => service('webpack_encore.tag_renderer'), + ], + ]), + ]) + + ->set('webpack_encore.entrypoint_lookup.cache_warmer', EntrypointCacheWarmer::class) + ->tag('kernel.cache_warmer') + ->args([ + abstract_arg(' build list of entrypoint paths'), + service('http_client')->nullOnInvalid(), + '%kernel.build_dir%/webpack_encore.cache.php', + ]) + + ->set('webpack_encore.cache', PhpArrayAdapter::class) + ->factory([PhpArrayAdapter::class, 'create']) + ->args([ + '%kernel.build_dir%/webpack_encore.cache.php', + service('cache.webpack_encore'), + ]) + + ->set('cache.webpack_encore') + ->parent('cache.system') + ->tag('cache.pool') + + ->set('webpack_encore.exception_listener', ExceptionListener::class) + ->tag('kernel.event_listener', ['event' => 'kernel.exception']) + ->args([ + service('webpack_encore.entrypoint_lookup_collection'), + abstract_arg('build list of build names'), + ]) + + ->set('webpack_encore.preload_assets_event_listener', PreLoadAssetsEventListener::class) + ->tag('kernel.event_subscriber') + ->args([ + service('webpack_encore.tag_renderer'), + ]) + + ->set(ResetAssetsEventListener::class) + ->tag('kernel.event_subscriber') + ->args([ + service('webpack_encore.entrypoint_lookup_collection'), + ]) + ; +}; diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml deleted file mode 100644 index 7327a97..0000000 --- a/src/Resources/config/services.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %kernel.build_dir%/webpack_encore.cache.php - - - - - %kernel.build_dir%/webpack_encore.cache.php - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index c293c40..045a7e1 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -328,7 +328,6 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa __DIR__.'/fixtures' => 'integration_test', ], 'strict_variables' => true, - 'exception_controller' => null, ]); $container->loadFromExtension('webpack_encore', [