mirror of
https://github.com/FriendsOfSymfony/FOSHttpCache.git
synced 2026-03-23 22:42:18 +01:00
Make CacheInvalidation.php work with Symfony 6 (#529)
Signatures of symfony 5 and 6 are incompatible for implementers.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -2,5 +2,6 @@
|
||||
.gitignore export-ignore
|
||||
.scrutinizer.yml export-ignore
|
||||
.travis.yml export-ignore
|
||||
.phpstan/ export-ignore
|
||||
phpunit.xml.dist export-ignore
|
||||
tests/ export-ignore
|
||||
|
||||
22
.phpstan/classAliases.php
Normal file
22
.phpstan/classAliases.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use FOS\HttpCache\SymfonyCache\CacheInvalidation;
|
||||
use FOS\HttpCache\SymfonyCache\Compatibility\CacheInvalidationS6;
|
||||
use FOS\HttpCache\SymfonyCache\Compatibility\CacheInvalidationLegacy;
|
||||
|
||||
/*
|
||||
* Hint phpstan on the class aliases.
|
||||
* Symfony 6 introduced a BC break in the signature of the protected method HttpKernelInterface::fetch.
|
||||
* Load the correct interface to match the signature.
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
|
||||
class_alias(
|
||||
CacheInvalidationS6::class,
|
||||
CacheInvalidation::class
|
||||
);
|
||||
} else {
|
||||
class_alias(
|
||||
CacheInvalidationLegacy::class,
|
||||
CacheInvalidation::class
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,8 @@ parameters:
|
||||
level: 1
|
||||
paths:
|
||||
- src
|
||||
bootstrapFiles:
|
||||
- .phpstan/classAliases.php
|
||||
excludePaths:
|
||||
analyseAndScan:
|
||||
# contains code to support legacy phpunit versions
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
parameters:
|
||||
level: 1
|
||||
bootstrapFiles:
|
||||
- .phpstan/classAliases.php
|
||||
paths:
|
||||
- tests
|
||||
|
||||
@@ -11,35 +11,38 @@
|
||||
|
||||
namespace FOS\HttpCache\SymfonyCache;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
|
||||
use function class_alias;
|
||||
use function class_exists;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
/**
|
||||
* Interface for a HttpCache that supports active cache invalidation.
|
||||
*/
|
||||
interface CacheInvalidation extends HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* Forwards the Request to the backend and determines whether the response should be stored.
|
||||
*
|
||||
* This methods is triggered when the cache missed or a reload is required.
|
||||
*
|
||||
* This method is present on HttpCache but must be public to allow event listeners to do
|
||||
* refresh operations.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param bool $catch Whether to process exceptions
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
public function fetch(Request $request, $catch = false);
|
||||
|
||||
/**
|
||||
* Gets the store for cached responses.
|
||||
*
|
||||
* @return StoreInterface $store The store used by the HttpCache
|
||||
*/
|
||||
public function getStore();
|
||||
if (interface_exists(CacheInvalidation::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Symfony 6 introduced a BC break in the signature of the protected method HttpKernelInterface::fetch.
|
||||
* Load the correct interface to match the signature.
|
||||
*/
|
||||
if (class_exists(Kernel::class) && Kernel::MAJOR_VERSION >= 6) {
|
||||
// Load class for Symfony >=6.0
|
||||
class_alias(
|
||||
Compatibility\CacheInvalidationS6::class,
|
||||
CacheInvalidation::class
|
||||
);
|
||||
} else {
|
||||
// Load class for any other cases
|
||||
class_alias(
|
||||
Compatibility\CacheInvalidationLegacy::class,
|
||||
CacheInvalidation::class
|
||||
);
|
||||
}
|
||||
|
||||
if (!interface_exists(CacheInvalidation::class)) {
|
||||
/**
|
||||
* Provide an empty interface for code scanners.
|
||||
*/
|
||||
interface SearchHandler extends HttpKernelInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
47
src/SymfonyCache/Compatibility/CacheInvalidationLegacy.php
Normal file
47
src/SymfonyCache/Compatibility/CacheInvalidationLegacy.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FOSHttpCache package.
|
||||
*
|
||||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace FOS\HttpCache\SymfonyCache\Compatibility;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Interface for a HttpCache that supports active cache invalidation.
|
||||
*
|
||||
* Method signature of `fetch` and `getStore` compatible with Symfony 5 and older.
|
||||
*/
|
||||
interface CacheInvalidationLegacy extends HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* Forwards the Request to the backend and determines whether the response should be stored.
|
||||
*
|
||||
* This methods is triggered when the cache missed or a reload is required.
|
||||
*
|
||||
* This method is present on HttpCache but must be public to allow event listeners to do
|
||||
* refresh operations.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param bool $catch Whether to process exceptions
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
public function fetch(Request $request, $catch = false);
|
||||
|
||||
/**
|
||||
* Gets the store for cached responses.
|
||||
*
|
||||
* @return StoreInterface $store The store used by the HttpCache
|
||||
*/
|
||||
public function getStore();
|
||||
}
|
||||
47
src/SymfonyCache/Compatibility/CacheInvalidationS6.php
Normal file
47
src/SymfonyCache/Compatibility/CacheInvalidationS6.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FOSHttpCache package.
|
||||
*
|
||||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace FOS\HttpCache\SymfonyCache\Compatibility;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Interface for a HttpCache that supports active cache invalidation.
|
||||
*
|
||||
* Method signature of `fetch` and `getStore` compatible with Symfony 6 or newer.
|
||||
*/
|
||||
interface CacheInvalidationS6 extends HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* Forwards the Request to the backend and determines whether the response should be stored.
|
||||
*
|
||||
* This methods is triggered when the cache missed or a reload is required.
|
||||
*
|
||||
* This method is present on HttpCache but must be public to allow event listeners to do
|
||||
* refresh operations.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param bool $catch Whether to process exceptions
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
public function fetch(Request $request, bool $catch = false): Response;
|
||||
|
||||
/**
|
||||
* Gets the store for cached responses.
|
||||
*
|
||||
* @return StoreInterface $store The store used by the HttpCache
|
||||
*/
|
||||
public function getStore(): StoreInterface;
|
||||
}
|
||||
Reference in New Issue
Block a user