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\HttpKernel\HttpKernelInterface ;
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache ;
use Symfony\Component\HttpKernel\HttpCache\Esi ;
use Symfony\Component\HttpKernel\HttpCache\Store ;
use Symfony\Component\HttpFoundation\Request ;
use Symfony\Component\HttpFoundation\Response ;
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
*/
2011-01-26 20:38:45 +00:00
abstract 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
/**
2012-03-28 16:41:21 +01:00
* @ param HttpKernelInterface $kernel An HttpKernelInterface instance
2012-07-06 17:52:14 +01:00
* @ 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-04-13 06:23:33 +01:00
$this -> kernel = $kernel ;
$this -> cacheDir = $cacheDir ;
2010-06-23 20:42:41 +01:00
2014-03-23 00:04:57 +00:00
parent :: __construct ( $kernel , $this -> createStore (), $this -> createSurrogate (), 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
2014-04-12 18:54:57 +01:00
* @ param bool $raw Whether to catch exceptions or not
2011-04-23 16:05:44 +01:00
* @ 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 );
2014-03-23 00:04:57 +00:00
$this -> getKernel () -> getContainer () -> set ( $this -> getSurrogate () -> getName (), $this -> getSurrogate ());
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 ();
}
2012-04-13 06:23:33 +01:00
2014-03-23 00:04:57 +00:00
protected function createSurrogate ()
{
2015-02-04 15:19:16 +00:00
return new Esi ();
2014-03-23 00:04:57 +00:00
}
/**
2015-06-07 07:33:05 +01:00
* Creates new ESI instance .
2014-03-23 00:04:57 +00:00
*
* @ return Esi
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 . Use createSurrogate () instead
2014-03-23 00:04:57 +00:00
*/
2012-04-13 08:04:04 +01:00
protected function createEsi ()
2012-04-13 06:23:33 +01:00
{
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.6 and will be removed in 3.0. Use createSurrogate() instead.' , E_USER_DEPRECATED );
2015-02-04 15:19:16 +00:00
return $this -> createSurrogate ();
2012-04-13 06:23:33 +01:00
}
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
}