|
11 | 11 |
|
12 | 12 | namespace FOS\HttpCache\SymfonyCache; |
13 | 13 |
|
14 | | -use Symfony\Component\HttpFoundation\Request; |
15 | | -use Symfony\Component\HttpFoundation\Response; |
16 | | -use Symfony\Component\HttpKernel\HttpCache\StoreInterface; |
| 14 | +use function class_alias; |
| 15 | +use function class_exists; |
17 | 16 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
| 17 | +use Symfony\Component\HttpKernel\Kernel; |
18 | 18 |
|
19 | | -/** |
20 | | - * Interface for a HttpCache that supports active cache invalidation. |
| 19 | +if (interface_exists(CacheInvalidation::class)) { |
| 20 | + return; |
| 21 | +} |
| 22 | + |
| 23 | +/* |
| 24 | + * Symfony 6 introduced a BC break in the signature of the protected method HttpKernelInterface::fetch. |
| 25 | + * Load the correct interface to match the signature. |
21 | 26 | */ |
22 | | -interface CacheInvalidation extends HttpKernelInterface |
23 | | -{ |
24 | | - /** |
25 | | - * Forwards the Request to the backend and determines whether the response should be stored. |
26 | | - * |
27 | | - * This methods is triggered when the cache missed or a reload is required. |
28 | | - * |
29 | | - * This method is present on HttpCache but must be public to allow event listeners to do |
30 | | - * refresh operations. |
31 | | - * |
32 | | - * @param Request $request A Request instance |
33 | | - * @param bool $catch Whether to process exceptions |
34 | | - * |
35 | | - * @return Response A Response instance |
36 | | - */ |
37 | | - public function fetch(Request $request, $catch = false); |
| 27 | +if (class_exists(Kernel::class) && Kernel::MAJOR_VERSION >= 6) { |
| 28 | + // Load class for Symfony >=6.0 |
| 29 | + class_alias( |
| 30 | + Compatibility\CacheInvalidationS6::class, |
| 31 | + CacheInvalidation::class |
| 32 | + ); |
| 33 | +} else { |
| 34 | + // Load class for any other cases |
| 35 | + class_alias( |
| 36 | + Compatibility\CacheInvalidationLegacy::class, |
| 37 | + CacheInvalidation::class |
| 38 | + ); |
| 39 | +} |
38 | 40 |
|
| 41 | +if (!interface_exists(CacheInvalidation::class)) { |
39 | 42 | /** |
40 | | - * Gets the store for cached responses. |
41 | | - * |
42 | | - * @return StoreInterface $store The store used by the HttpCache |
| 43 | + * Provide an empty interface for code scanners. |
43 | 44 | */ |
44 | | - public function getStore(); |
| 45 | + interface SearchHandler extends HttpKernelInterface |
| 46 | + { |
| 47 | + } |
45 | 48 | } |
0 commit comments