|
15 | 15 |
|
16 | 16 | use Sylius\Bundle\CoreBundle\Routing\Matcher\Dumper\PhpMatcherDumper; |
17 | 17 | use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; |
18 | | -use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher; |
19 | | -use Symfony\Bundle\FrameworkBundle\Routing\Router; |
20 | 18 | use Symfony\Component\Config\FileLocator; |
21 | 19 | use Symfony\Component\Config\Loader\LoaderInterface; |
| 20 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
22 | 21 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
23 | | -use Symfony\Component\DependencyInjection\Definition; |
24 | 22 | use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
25 | 23 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
26 | | -use Symfony\Component\DependencyInjection\Reference; |
27 | 24 | use Symfony\Component\HttpKernel\Kernel; |
28 | | -use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; |
29 | | -use Symfony\Component\Routing\Generator\UrlGenerator; |
30 | 25 |
|
31 | | -final class SyliusCoreExtension extends AbstractResourceExtension implements PrependExtensionInterface |
| 26 | +final class SyliusCoreExtension extends AbstractResourceExtension implements PrependExtensionInterface, CompilerPassInterface |
32 | 27 | { |
33 | 28 | /** @var array */ |
34 | 29 | private static $bundles = [ |
@@ -68,11 +63,6 @@ public function load(array $config, ContainerBuilder $container): void |
68 | 63 | if ('test' === $env || 'test_cached' === $env) { |
69 | 64 | $loader->load('test_services.xml'); |
70 | 65 | } |
71 | | - |
72 | | - // This service is temporarily overwritten, due to problems with PhpMatcherDumper in Symfony 4.1.8 and 4.1.9 |
73 | | - if (Kernel::VERSION === '4.1.8' || Kernel::VERSION === '4.1.9') { |
74 | | - $this->overrideRouterDefinition($container); |
75 | | - } |
76 | 66 | } |
77 | 67 |
|
78 | 68 | /** |
@@ -104,30 +94,17 @@ private function prependHwiOauth(ContainerBuilder $container, LoaderInterface $l |
104 | 94 | $loader->load('services/integrations/hwi_oauth.xml'); |
105 | 95 | } |
106 | 96 |
|
107 | | - private function overrideRouterDefinition(ContainerBuilder $container): void |
| 97 | + public function process(ContainerBuilder $container): void |
108 | 98 | { |
109 | | - $routerDefinition = new Definition(Router::class); |
110 | | - $routerDefinition->addTag('monolog.logger', ['channel' => 'router']); |
111 | | - $routerDefinition->addTag('container.service_subscriber', ['id' => 'routing.loader']); |
112 | | - $routerDefinition->addArgument(new Reference('Psr\Container\ContainerInterface')); |
113 | | - $routerDefinition->addArgument($container->getParameter('router.resource')); |
114 | | - $routerDefinition->addArgument([ |
115 | | - 'cache_dir' => $container->getParameter('kernel.cache_dir'), |
116 | | - 'debug' => $container->getParameter('kernel.debug'), |
117 | | - 'generator_class' => UrlGenerator::class, |
118 | | - 'generator_base_class' => UrlGenerator::class, |
119 | | - 'generator_dumper_class' => PhpGeneratorDumper::class, |
120 | | - 'generator_cache_class' => $container->getParameter('router.cache_class_prefix') . 'UrlGenerator', |
121 | | - 'matcher_class' => RedirectableUrlMatcher::class, |
122 | | - 'matcher_base_class' => RedirectableUrlMatcher::class, |
123 | | - 'matcher_dumper_class' => PhpMatcherDumper::class, |
124 | | - 'matcher_cache_class' => $container->getParameter('router.cache_class_prefix') . 'UrlMatcher', |
125 | | - ]); |
126 | | - $routerDefinition->addArgument((new Reference('router.request_context', \Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); |
127 | | - $routerDefinition->addArgument((new Reference('parameter_bag', \Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); |
128 | | - $routerDefinition->addArgument((new Reference('logger', \Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); |
129 | | - $routerDefinition->addMethodCall('setConfigCacheFactory', [new Reference('config_cache_factory')]); |
130 | | - |
131 | | - $container->setDefinition('router.default', $routerDefinition); |
| 99 | + // Should be removed after PhpMatcherDumper is fixed in an another Symfony patch release |
| 100 | + if (!in_array(Kernel::VERSION, ['4.1.8', '4.1.9'], true)) { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + $routerDefinition = $container->findDefinition('router.default'); |
| 105 | + $routerDefinition->replaceArgument(2, array_merge( |
| 106 | + $routerDefinition->getArgument(2), |
| 107 | + ['matcher_dumper_class' => PhpMatcherDumper::class] |
| 108 | + )); |
132 | 109 | } |
133 | 110 | } |
0 commit comments