Skip to content

Commit a1314d4

Browse files
committed
Update dispatch call
1 parent 99e856b commit a1314d4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/CacheInvalidator.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,25 @@ public function flush()
311311
$event = new Event();
312312
$event->setException($exception);
313313
if ($exception instanceof ProxyResponseException) {
314-
$this->getEventDispatcher()->dispatch(Events::PROXY_RESPONSE_ERROR, $event);
314+
$this->dispatch($event, Events::PROXY_RESPONSE_ERROR);
315315
} elseif ($exception instanceof ProxyUnreachableException) {
316-
$this->getEventDispatcher()->dispatch(Events::PROXY_UNREACHABLE_ERROR, $event);
316+
$this->dispatch($event, Events::PROXY_UNREACHABLE_ERROR);
317317
}
318318
}
319319

320320
throw $exceptions;
321321
}
322322
}
323+
324+
private function dispatch(Event $event, $eventName)
325+
{
326+
// LegacyEventDispatcherProxy exists in Symfony >= 4.3
327+
if (class_exists(LegacyEventDispatcherProxy::class)) {
328+
// New Symfony 4.3 EventDispatcher signature
329+
$this->getEventDispatcher()->dispatch($event, $eventName);
330+
} else {
331+
// Old EventDispatcher signature
332+
$this->getEventDispatcher()->dispatch($eventName, $event);
333+
}
334+
}
323335
}

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,16 @@ protected function dispatch($name, Request $request, Response $response = null,
145145
{
146146
if ($this->getEventDispatcher()->hasListeners($name)) {
147147
$event = new CacheEvent($this, $request, $response, $requestType);
148-
$this->getEventDispatcher()->dispatch($name, $event);
148+
149+
// LegacyEventDispatcherProxy exists in Symfony >= 4.3
150+
if (class_exists(LegacyEventDispatcherProxy::class)) {
151+
// New Symfony 4.3 EventDispatcher signature
152+
$this->getEventDispatcher()->dispatch($event, $name);
153+
} else {
154+
// Old EventDispatcher signature
155+
$this->getEventDispatcher()->dispatch($name, $event);
156+
}
157+
149158
$response = $event->getResponse();
150159
}
151160

0 commit comments

Comments
 (0)