From 0d550ca032dce0c199d03a550b55cad28de253ec Mon Sep 17 00:00:00 2001 From: Svyatoslav Varpikhovsky Date: Tue, 24 Jan 2023 18:01:50 +0200 Subject: [PATCH] FRW-19 Support Symfony packages v6. (#2280) FRW-19 Support Symfony v6 --- phpstan.neon | 2 ++ .../ServiceControllerResolver.php | 6 ++---- .../Plugin/Provider/WidgetTagServiceProvider.php | 16 +++++++++++++++- .../ShopApplicationTwigEventSubscriber.php | 16 +++++++++++++++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 97d83ec..ecd9e25 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -17,5 +17,7 @@ parameters: - '#Comparison operation "<" between [1-9] and 3 is always (true|false).#' - '#Method .+\\WidgetTagTwigPlugin::openWidgetContext\(\) should return .+\\WidgetInterface\|null but returns .+\\WidgetPluginInterface\|.+\\WidgetInterface\|null.#' - '#Parameter \#2 \$string of function explode expects string, string\|false given.#' + - '#^Call to function method_exists\(\) with Symfony\\Component\\HttpKernel\\Event\\ViewEvent and#' + - '#Call to an undefined method Symfony\\Component\\HttpKernel\\Event\\ViewEvent\:\:isMainRequest\(\).#' excludePaths: - '%rootDir%/../../../vendor/spryker/spryker-shop/Bundles/ShopApplication/src/SprykerShop/Yves/ShopApplication/Plugin/AbstractTwigExtensionPlugin.php' diff --git a/src/SprykerShop/Yves/ShopApplication/ControllerResolver/ServiceControllerResolver.php b/src/SprykerShop/Yves/ShopApplication/ControllerResolver/ServiceControllerResolver.php index 694f0e7..edafa53 100644 --- a/src/SprykerShop/Yves/ShopApplication/ControllerResolver/ServiceControllerResolver.php +++ b/src/SprykerShop/Yves/ShopApplication/ControllerResolver/ServiceControllerResolver.php @@ -39,7 +39,7 @@ public function __construct(ControllerResolverInterface $controllerResolver, Cal /** * @inheritDoc */ - public function getController(Request $request) + public function getController(Request $request): callable|false { $controller = $request->attributes->get('_controller', null); @@ -52,14 +52,12 @@ public function getController(Request $request) } /** - * {@inheritDoc} - * * @param \Symfony\Component\HttpFoundation\Request $request * @param callable $controller * * @return array */ - public function getArguments(Request $request, $controller) + public function getArguments(Request $request, callable $controller): array { if (method_exists($this->controllerResolver, 'getArguments')) { return $this->controllerResolver->getArguments($request, $controller); diff --git a/src/SprykerShop/Yves/ShopApplication/Plugin/Provider/WidgetTagServiceProvider.php b/src/SprykerShop/Yves/ShopApplication/Plugin/Provider/WidgetTagServiceProvider.php index 30eb8d0..5c507a1 100644 --- a/src/SprykerShop/Yves/ShopApplication/Plugin/Provider/WidgetTagServiceProvider.php +++ b/src/SprykerShop/Yves/ShopApplication/Plugin/Provider/WidgetTagServiceProvider.php @@ -176,7 +176,7 @@ protected function onKernelView(ViewEvent $event, SprykerApplication $applicatio /** @var \Twig\Environment $twig */ $twig = $application['twig']; - if (!$event->isMasterRequest()) { + if (!$this->isMainRequest($event)) { $masterGlobalView = $this->getGlobalView($twig); } @@ -230,4 +230,18 @@ protected function getViewParameters(ViewInterface $view): array return []; } + + /** + * @param \Symfony\Component\HttpKernel\Event\ViewEvent $event + * + * @return bool + */ + protected function isMainRequest(ViewEvent $event): bool + { + if (method_exists($event, 'isMasterRequest')) { + return $event->isMasterRequest(); + } + + return $event->isMainRequest(); + } } diff --git a/src/SprykerShop/Yves/ShopApplication/Subscriber/ShopApplicationTwigEventSubscriber.php b/src/SprykerShop/Yves/ShopApplication/Subscriber/ShopApplicationTwigEventSubscriber.php index 49584fa..37a3b47 100644 --- a/src/SprykerShop/Yves/ShopApplication/Subscriber/ShopApplicationTwigEventSubscriber.php +++ b/src/SprykerShop/Yves/ShopApplication/Subscriber/ShopApplicationTwigEventSubscriber.php @@ -108,7 +108,7 @@ public function onKernelView(ViewEvent $event): void $masterGlobalView = null; if ($result instanceof ViewInterface) { - if (!$event->isMasterRequest()) { + if (!$this->isMainRequest($event)) { $masterGlobalView = $this->getGlobalView(); } @@ -270,4 +270,18 @@ protected function addWidgetContainerRegister(WidgetContainerInterface $result): { $this->widgetContainerRegistry->add($result); } + + /** + * @param \Symfony\Component\HttpKernel\Event\ViewEvent $event + * + * @return bool + */ + protected function isMainRequest(ViewEvent $event): bool + { + if (method_exists($event, 'isMasterRequest')) { + return $event->isMasterRequest(); + } + + return $event->isMainRequest(); + } }