From 254159b17be408bb9fce828240e739ea46fa3e9e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 23 Apr 2021 13:59:35 -0400 Subject: [PATCH 1/2] handle request deprecations --- src/EventListener/PreLoadAssetsEventListener.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/EventListener/PreLoadAssetsEventListener.php b/src/EventListener/PreLoadAssetsEventListener.php index 1a6461ab..7b45d968 100644 --- a/src/EventListener/PreLoadAssetsEventListener.php +++ b/src/EventListener/PreLoadAssetsEventListener.php @@ -29,12 +29,11 @@ public function __construct(TagRenderer $tagRenderer) $this->tagRenderer = $tagRenderer; } - /** - * @param ResponseEvent $event - */ - public function onKernelResponse($event) + public function onKernelResponse(ResponseEvent $event): void { - if (!$event->isMasterRequest()) { + $mainRequestMethod = method_exists($event, 'isMainRequest') ? 'isMainRequest' : 'isMasterRequest'; + + if (!$event->$mainRequestMethod()) { return; } @@ -76,7 +75,7 @@ class_exists(GenericLinkProvider::class) ? new GenericLinkProvider() : new FigGe $request->attributes->set('_links', $linkProvider); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ // must run before AddLinkHeaderListener From 0781d0c8220712721519b6a0fa6e5a7bb5373eb1 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 23 Apr 2021 14:05:12 -0400 Subject: [PATCH 2/2] add return types where possible --- src/CacheWarmer/EntrypointCacheWarmer.php | 2 +- src/DependencyInjection/Configuration.php | 2 +- src/DependencyInjection/WebpackEncoreExtension.php | 2 +- src/EventListener/ExceptionListener.php | 2 +- src/EventListener/PreLoadAssetsEventListener.php | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CacheWarmer/EntrypointCacheWarmer.php b/src/CacheWarmer/EntrypointCacheWarmer.php index edced6e4..6a31ed84 100644 --- a/src/CacheWarmer/EntrypointCacheWarmer.php +++ b/src/CacheWarmer/EntrypointCacheWarmer.php @@ -28,7 +28,7 @@ public function __construct(array $cacheKeys, string $phpArrayFile, CacheItemPoo /** * {@inheritdoc} */ - protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter) + protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter): bool { foreach ($this->cacheKeys as $cacheKey => $path) { // If the file does not exist then just skip past this entry point. diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 87b5ef1a..2fd47d4d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -16,7 +16,7 @@ final class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('webpack_encore'); /** @var ArrayNodeDefinition $rootNode */ diff --git a/src/DependencyInjection/WebpackEncoreExtension.php b/src/DependencyInjection/WebpackEncoreExtension.php index 53a68dce..91b13175 100644 --- a/src/DependencyInjection/WebpackEncoreExtension.php +++ b/src/DependencyInjection/WebpackEncoreExtension.php @@ -25,7 +25,7 @@ final class WebpackEncoreExtension extends Extension { private const ENTRYPOINTS_FILE_NAME = 'entrypoints.json'; - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); $loader->load('services.xml'); diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 57a851ee..e5223a90 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -23,7 +23,7 @@ public function __construct(EntrypointLookupCollection $entrypointLookupCollecti $this->buildNames = $buildNames; } - public function onKernelException() + public function onKernelException(): void { foreach ($this->buildNames as $buildName) { $this->entrypointLookupCollection->getEntrypointLookup($buildName)->reset(); diff --git a/src/EventListener/PreLoadAssetsEventListener.php b/src/EventListener/PreLoadAssetsEventListener.php index 7b45d968..cb0aa52f 100644 --- a/src/EventListener/PreLoadAssetsEventListener.php +++ b/src/EventListener/PreLoadAssetsEventListener.php @@ -31,6 +31,7 @@ public function __construct(TagRenderer $tagRenderer) public function onKernelResponse(ResponseEvent $event): void { + // Handle deprecated `KernelEvent::isMasterRequest() - Can be removed when Symfony < 5.3 support is dropped. $mainRequestMethod = method_exists($event, 'isMainRequest') ? 'isMainRequest' : 'isMasterRequest'; if (!$event->$mainRequestMethod()) {