Skip to content

Commit d6aa9e8

Browse files
committed
Use LegacyEventDispatcherProxy for Symfony 4.3
1 parent 01d87fa commit d6aa9e8

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/CacheInvalidator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use FOS\HttpCache\ProxyClient\Symfony;
2626
use Symfony\Component\EventDispatcher\EventDispatcher;
2727
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
28+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2829
use Toflar\Psr6HttpCacheStore\Psr6Store;
2930

3031
/**
@@ -143,7 +144,11 @@ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
143144
public function getEventDispatcher()
144145
{
145146
if (!$this->eventDispatcher) {
146-
$this->eventDispatcher = new EventDispatcher();
147+
if (class_exists(LegacyEventDispatcherProxy::class)) {
148+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate(new EventDispatcher());
149+
} else {
150+
$this->eventDispatcher = new EventDispatcher();
151+
}
147152
}
148153

149154
return $this->eventDispatcher;

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\EventDispatcher\EventDispatcher;
1515
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpFoundation\Response;
1920
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -54,8 +55,12 @@ trait EventDispatchingHttpCache
5455
*/
5556
public function getEventDispatcher()
5657
{
57-
if (null === $this->eventDispatcher) {
58-
$this->eventDispatcher = new EventDispatcher();
58+
if (!$this->eventDispatcher) {
59+
if (class_exists(LegacyEventDispatcherProxy::class)) {
60+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate(new EventDispatcher());
61+
} else {
62+
$this->eventDispatcher = new EventDispatcher();
63+
}
5964
}
6065

6166
return $this->eventDispatcher;

tests/Unit/CacheInvalidatorTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Psr\Http\Message\ResponseInterface;
3333
use Psr\Log\LoggerInterface;
3434
use Symfony\Component\EventDispatcher\EventDispatcher;
35+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
3536

3637
class CacheInvalidatorTest extends TestCase
3738
{
@@ -257,8 +258,13 @@ public function testEventDispatcher()
257258
/** @var MockInterface|Varnish $proxyClient */
258259
$proxyClient = \Mockery::mock(Varnish::class);
259260

261+
if (class_exists(LegacyEventDispatcherProxy::class)) {
262+
$eventDispatcher = LegacyEventDispatcherProxy::decorate(new EventDispatcher());
263+
} else {
264+
$eventDispatcher = new EventDispatcher();
265+
}
266+
260267
$cacheInvalidator = new CacheInvalidator($proxyClient);
261-
$eventDispatcher = new EventDispatcher();
262268
$cacheInvalidator->setEventDispatcher($eventDispatcher);
263269
$this->assertSame($eventDispatcher, $cacheInvalidator->getEventDispatcher());
264270
}
@@ -268,8 +274,13 @@ public function testEventDispatcherImmutable()
268274
/** @var MockInterface|Varnish $proxyClient */
269275
$proxyClient = \Mockery::mock(Varnish::class);
270276

277+
if (class_exists(LegacyEventDispatcherProxy::class)) {
278+
$eventDispatcher = LegacyEventDispatcherProxy::decorate(new EventDispatcher());
279+
} else {
280+
$eventDispatcher = new EventDispatcher();
281+
}
282+
271283
$cacheInvalidator = new CacheInvalidator($proxyClient);
272-
$eventDispatcher = new EventDispatcher();
273284
$cacheInvalidator->setEventDispatcher($eventDispatcher);
274285
$this->expectException(\Exception::class);
275286
$cacheInvalidator->setEventDispatcher($eventDispatcher);

0 commit comments

Comments
 (0)