2010-06-23 20:42:41 +01:00
|
|
|
<?php
|
|
|
|
|
2011-01-26 20:38:45 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\HttpCache;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
2011-01-26 20:38:45 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
|
|
|
|
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
|
|
|
use Symfony\Component\HttpKernel\HttpCache\Store;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2010-06-23 20:42:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2011-01-26 20:38:45 +00:00
|
|
|
abstract class HttpCache extends BaseHttpCache
|
2010-06-23 20:42:41 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2012-03-28 16:41:21 +01:00
|
|
|
* @param HttpKernelInterface $kernel An HttpKernelInterface instance
|
|
|
|
* @param String $cacheDir The cache directory (default used if null)
|
2010-06-23 20:42:41 +01:00
|
|
|
*/
|
2012-03-28 16:41:21 +01:00
|
|
|
public function __construct(HttpKernelInterface $kernel, $cacheDir = null)
|
2010-06-23 20:42:41 +01:00
|
|
|
{
|
2012-03-28 16:41:21 +01:00
|
|
|
if ($cacheDir) {
|
|
|
|
$store = new Store($cacheDir);
|
|
|
|
} else {
|
|
|
|
$store = new Store($kernel->getCacheDir().'/http_cache');
|
|
|
|
}
|
|
|
|
|
2010-06-23 20:42:41 +01:00
|
|
|
$esi = new Esi();
|
|
|
|
|
2011-01-16 02:24:06 +00:00
|
|
|
parent::__construct($kernel, $store, $esi, array_merge(array('debug' => $kernel->isDebug()), $this->getOptions()));
|
2010-06-23 20:42:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forwards the Request to the backend and returns the Response.
|
|
|
|
*
|
2011-04-23 16:05:44 +01:00
|
|
|
* @param Request $request A Request instance
|
|
|
|
* @param Boolean $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();
|
|
|
|
$this->getKernel()->getContainer()->set('cache', $this);
|
2011-03-28 12:45:23 +01:00
|
|
|
$this->getKernel()->getContainer()->set('esi', $this->getEsi());
|
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()
|
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|