mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-27 06:04:12 +01:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Store;
|
||||
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
|
||||
use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
@@ -23,64 +25,77 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class HttpCache extends BaseHttpCache
|
||||
class HttpCache extends BaseHttpCache
|
||||
{
|
||||
protected $cacheDir;
|
||||
protected $kernel;
|
||||
|
||||
private $store;
|
||||
private $surrogate;
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @param KernelInterface $kernel A KernelInterface instance
|
||||
* @param string $cacheDir The cache directory (default used if null)
|
||||
* @param string|StoreInterface $cache The cache directory (default used if null) or the storage instance
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel, $cacheDir = null)
|
||||
public function __construct(KernelInterface $kernel, $cache = null, SurrogateInterface $surrogate = null, array $options = null)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->cacheDir = $cacheDir;
|
||||
$this->surrogate = $surrogate;
|
||||
$this->options = $options ?? [];
|
||||
|
||||
$isDebug = $kernel->isDebug();
|
||||
$options = ['debug' => $isDebug];
|
||||
|
||||
if ($isDebug) {
|
||||
$options['stale_if_error'] = 0;
|
||||
if ($cache instanceof StoreInterface) {
|
||||
$this->store = $cache;
|
||||
} elseif (null !== $cache && !\is_string($cache)) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a SurrogateInterface, "%s" given.', __METHOD__, get_debug_type($cache)));
|
||||
} else {
|
||||
$this->cacheDir = $cache;
|
||||
}
|
||||
|
||||
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($options, $this->getOptions()));
|
||||
if (null === $options && $kernel->isDebug()) {
|
||||
$this->options = ['debug' => true];
|
||||
}
|
||||
|
||||
if ($this->options['debug'] ?? false) {
|
||||
$this->options += ['stale_if_error' => 0];
|
||||
}
|
||||
|
||||
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($this->options, $this->getOptions()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the Request to the backend and returns the Response.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param bool $raw Whether to catch exceptions or not
|
||||
* @param Response $entry A Response instance (the stale entry if present, null otherwise)
|
||||
*
|
||||
* @return Response A Response instance
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function forward(Request $request, $raw = false, Response $entry = null)
|
||||
protected function forward(Request $request, bool $catch = false, Response $entry = null)
|
||||
{
|
||||
$this->getKernel()->boot();
|
||||
$this->getKernel()->getContainer()->set('cache', $this);
|
||||
|
||||
return parent::forward($request, $raw, $entry);
|
||||
return parent::forward($request, $catch, $entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of options to customize the Cache configuration.
|
||||
*
|
||||
* @return array An array of options
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SurrogateInterface
|
||||
*/
|
||||
protected function createSurrogate()
|
||||
{
|
||||
return new Esi();
|
||||
return $this->surrogate ?? new Esi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StoreInterface
|
||||
*/
|
||||
protected function createStore()
|
||||
{
|
||||
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
|
||||
return $this->store ?? new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user