Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10de89a

Browse files
authored
bug #10038 Fix the build on 1.3 by more flexible router overriding (pamil)
This PR was merged into the 1.2 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.2 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md file --> | Related tickets | related to #10020 | License | MIT <!-- - Bug fixes must be submitted against the 1.1 or 1.2 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set --> Commits ------- 217e97e Fix the build on 1.3 by more flexible router overriding
2 parents fccb9c7 + 217e97e commit 10de89a

1 file changed

Lines changed: 13 additions & 36 deletions

File tree

src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@
1515

1616
use Sylius\Bundle\CoreBundle\Routing\Matcher\Dumper\PhpMatcherDumper;
1717
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
18-
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
19-
use Symfony\Bundle\FrameworkBundle\Routing\Router;
2018
use Symfony\Component\Config\FileLocator;
2119
use Symfony\Component\Config\Loader\LoaderInterface;
20+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2221
use Symfony\Component\DependencyInjection\ContainerBuilder;
23-
use Symfony\Component\DependencyInjection\Definition;
2422
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
2523
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
26-
use Symfony\Component\DependencyInjection\Reference;
2724
use Symfony\Component\HttpKernel\Kernel;
28-
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
29-
use Symfony\Component\Routing\Generator\UrlGenerator;
3025

31-
final class SyliusCoreExtension extends AbstractResourceExtension implements PrependExtensionInterface
26+
final class SyliusCoreExtension extends AbstractResourceExtension implements PrependExtensionInterface, CompilerPassInterface
3227
{
3328
/** @var array */
3429
private static $bundles = [
@@ -68,11 +63,6 @@ public function load(array $config, ContainerBuilder $container): void
6863
if ('test' === $env || 'test_cached' === $env) {
6964
$loader->load('test_services.xml');
7065
}
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-
}
7666
}
7767

7868
/**
@@ -104,30 +94,17 @@ private function prependHwiOauth(ContainerBuilder $container, LoaderInterface $l
10494
$loader->load('services/integrations/hwi_oauth.xml');
10595
}
10696

107-
private function overrideRouterDefinition(ContainerBuilder $container): void
97+
public function process(ContainerBuilder $container): void
10898
{
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+
));
132109
}
133110
}

0 commit comments

Comments
 (0)