Skip to content

Commit a01685f

Browse files
committed
Provide Symfony HttpCache as trait
1 parent 843ead4 commit a01685f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111

1212
namespace FOS\HttpCache\SymfonyCache;
1313

14-
use Symfony\Component\HttpFoundation\Response;
15-
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
1614
use Symfony\Component\EventDispatcher\EventDispatcher;
1715
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1816
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1917
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Response;
2019
use Symfony\Component\HttpKernel\HttpKernelInterface;
2120

2221
/**
23-
* Base class for enhanced Symfony reverse proxy based on the symfony component.
22+
* Trait for enhanced Symfony reverse proxy based on the symfony component.
2423
*
2524
* <b>When using FOSHttpCacheBundle, look at FOS\HttpCacheBundle\HttpCache instead.</b>
2625
*
@@ -31,7 +30,7 @@
3130
*
3231
* {@inheritdoc}
3332
*/
34-
abstract class EventDispatchingHttpCache extends HttpCache implements CacheInvalidationInterface
33+
trait EventDispatchingHttpCache
3534
{
3635
/**
3736
* @var EventDispatcherInterface

tests/Functional/Fixtures/Symfony/AppCache.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespace FOS\HttpCache\Tests\Functional\Fixtures\Symfony;
44

5+
use FOS\HttpCache\SymfonyCache\CacheInvalidationInterface;
56
use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache;
67
use Symfony\Component\HttpFoundation\Request;
8+
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
79
use Symfony\Component\HttpKernel\HttpKernelInterface;
810

9-
class AppCache extends EventDispatchingHttpCache
11+
class AppCache extends HttpCache implements CacheInvalidationInterface
1012
{
13+
use EventDispatchingHttpCache;
14+
1115
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
1216
{
1317
$response = parent::handle($request, $type, $catch);
@@ -25,4 +29,14 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
2529

2630
return $response;
2731
}
32+
33+
/**
34+
* Made public to allow event subscribers to do refresh operations.
35+
*
36+
* {@inheritDoc}
37+
*/
38+
public function fetch(Request $request, $catch = false)
39+
{
40+
return parent::fetch($request, $catch);
41+
}
2842
}

0 commit comments

Comments
 (0)