Skip to content

Commit e80fa83

Browse files
author
Olivier Dolbeau
committed
Use class_exists to deal with next events class
1 parent 7d8736d commit e80fa83

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

EventListener/AutoAddMissingTranslations.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,8 @@ public function __construct(StorageService $storage, DataCollectorTranslator $tr
4141
$this->storage = $storage;
4242
}
4343

44-
public function onTerminate($event): void
44+
public function onTerminate(TerminateEvent $event): void
4545
{
46-
// FilterResponseEvent have been renamed into ResponseEvent in sf 4.3
47-
// Use this class to type hint event & remove the following condition once sf ^4.3 become the minimum supported version.
48-
// @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel
49-
if (!$event instanceof PostResponseEvent && !$event instanceof TerminateEvent) {
50-
throw new \InvalidArgumentException('Unknown given event.');
51-
}
52-
5346
if (null === $this->dataCollector) {
5447
return;
5548
}
@@ -63,3 +56,10 @@ public function onTerminate($event): void
6356
}
6457
}
6558
}
59+
60+
// FilterResponseEvent have been renamed into ResponseEvent in sf 4.3
61+
// @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel
62+
// To be removed once sf ^4.3 become the minimum supported version.
63+
if (!\class_exists(TerminateEvent::class) && \class_exists(FilterResponseEvent::class)) {
64+
\class_alias(FilterResponseEvent::class, TerminateEvent::class);
65+
}

EventListener/EditInPlaceResponseListener.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,8 @@ public function __construct(ActivatorInterface $activator, UrlGeneratorInterface
7575
$this->showUntranslatable = $showUntranslatable;
7676
}
7777

78-
public function onKernelResponse($event): void
78+
public function onKernelResponse(ResponseEvent $event): void
7979
{
80-
// FilterResponseEvent have been renamed into ResponseEvent in sf 4.3
81-
// Use this class to type hint event & remove the following condition once sf ^4.3 become the minimum supported version.
82-
// @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel
83-
if (!$event instanceof FilterResponseEvent && !$event instanceof ResponseEvent) {
84-
throw new \InvalidArgumentException('Unknown given event.');
85-
}
86-
8780
$request = $event->getRequest();
8881

8982
if (!$this->activator->checkRequest($request)) {
@@ -135,3 +128,10 @@ public function onKernelResponse($event): void
135128
$event->getResponse()->setContent($content);
136129
}
137130
}
131+
132+
// FilterResponseEvent have been renamed into ResponseEvent in sf 4.3
133+
// @see https://github.com/symfony/symfony/blob/master/UPGRADE-4.3.md#httpkernel
134+
// To be removed once sf ^4.3 become the minimum supported version.
135+
if (!\class_exists(ResponseEvent::class) && \class_exists(FilterResponseEvent::class)) {
136+
\class_alias(FilterResponseEvent::class, ResponseEvent::class);
137+
}

phpstan-baseline.neon

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,15 @@ parameters:
7676
path: DependencyInjection/TranslationExtension.php
7777

7878
-
79-
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\PostResponseEvent not found\\.$#"
80-
count: 1
79+
message: "#^Class Translation\\\\Bundle\\\\EventListener\\\\FilterResponseEvent not found\\.$#"
80+
count: 2
8181
path: EventListener/AutoAddMissingTranslations.php
8282

8383
-
8484
message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterResponseEvent not found\\.$#"
85-
count: 1
86-
path: EventListener/EditInPlaceResponseListener.php
87-
88-
-
89-
message: "#^Call to method getRequest\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterResponseEvent\\.$#"
9085
count: 2
9186
path: EventListener/EditInPlaceResponseListener.php
9287

93-
-
94-
message: "#^Call to method getResponse\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterResponseEvent\\.$#"
95-
count: 3
96-
path: EventListener/EditInPlaceResponseListener.php
97-
9888
-
9989
message: "#^Class Symfony\\\\Component\\\\Translation\\\\TranslatorInterface not found\\.$#"
10090
count: 1

0 commit comments

Comments
 (0)