2010-06-23 20:42:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-06-23 20:42:41 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-04-02 04:52:14 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\HttpCache;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2018-07-26 10:03:18 +01:00
|
|
|
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
|
|
|
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
|
|
|
|
use Symfony\Component\HttpKernel\HttpCache\Store;
|
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
2012-04-02 04:52:14 +01:00
|
|
|
|
2010-06-23 20:42:41 +01:00
|
|
|
/**
|
2011-12-13 07:50:54 +00:00
|
|
|
* Manages HTTP cache objects in a Container.
|
2010-06-23 20:42:41 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-06-23 20:42:41 +01:00
|
|
|
*/
|
2018-04-02 12:58:37 +01:00
|
|
|
class HttpCache extends BaseHttpCache
|
2010-06-23 20:42:41 +01:00
|
|
|
{
|
2012-04-13 06:23:33 +01:00
|
|
|
protected $cacheDir;
|
|
|
|
protected $kernel;
|
|
|
|
|
2010-06-23 20:42:41 +01:00
|
|
|
/**
|
2019-08-06 06:23:17 +01:00
|
|
|
* @param string $cacheDir The cache directory (default used if null)
|
2010-06-23 20:42:41 +01:00
|
|
|
*/
|
2018-03-19 22:35:49 +00:00
|
|
|
public function __construct(KernelInterface $kernel, string $cacheDir = null)
|
2010-06-23 20:42:41 +01:00
|
|
|
{
|
2012-04-13 06:23:33 +01:00
|
|
|
$this->kernel = $kernel;
|
|
|
|
$this->cacheDir = $cacheDir;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge(['debug' => $kernel->isDebug()], $this->getOptions()));
|
2010-06-23 20:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forwards the Request to the backend and returns the Response.
|
|
|
|
*
|
2019-08-06 06:23:17 +01:00
|
|
|
* @param bool $raw Whether to catch exceptions or not
|
|
|
|
* @param Response $entry A Response instance (the stale entry if present, null otherwise)
|
2010-06-23 20:42:41 +01:00
|
|
|
*
|
2010-07-27 14:33:28 +01:00
|
|
|
* @return Response A Response instance
|
2010-06-23 20:42:41 +01:00
|
|
|
*/
|
|
|
|
protected function forward(Request $request, $raw = false, Response $entry = null)
|
|
|
|
{
|
2011-03-28 10:58:16 +01:00
|
|
|
$this->getKernel()->boot();
|
2017-07-18 12:58:52 +01:00
|
|
|
$this->getKernel()->getContainer()->set('cache', $this);
|
2010-06-23 20:42:41 +01:00
|
|
|
|
|
|
|
return parent::forward($request, $raw, $entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of options to customize the Cache configuration.
|
|
|
|
*
|
|
|
|
* @return array An array of options
|
|
|
|
*/
|
|
|
|
protected function getOptions()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
return [];
|
2010-06-23 20:42:41 +01:00
|
|
|
}
|
2012-04-13 06:23:33 +01:00
|
|
|
|
2014-03-23 00:04:57 +00:00
|
|
|
protected function createSurrogate()
|
2012-04-13 06:23:33 +01:00
|
|
|
{
|
|
|
|
return new Esi();
|
|
|
|
}
|
|
|
|
|
2012-04-13 08:04:04 +01:00
|
|
|
protected function createStore()
|
2012-04-13 06:23:33 +01:00
|
|
|
{
|
|
|
|
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
|
|
|
|
}
|
2010-06-23 20:42:41 +01:00
|
|
|
}
|