vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php line 57

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\HttpCache;
  11. use Symfony\Component\HttpKernel\KernelInterface;
  12. use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
  13. use Symfony\Component\HttpKernel\HttpCache\Esi;
  14. use Symfony\Component\HttpKernel\HttpCache\Store;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. /**
  18.  * Manages HTTP cache objects in a Container.
  19.  *
  20.  * @author Fabien Potencier <fabien@symfony.com>
  21.  */
  22. abstract class HttpCache extends BaseHttpCache
  23. {
  24.     protected $cacheDir;
  25.     protected $kernel;
  26.     /**
  27.      * @param KernelInterface $kernel   A KernelInterface instance
  28.      * @param string          $cacheDir The cache directory (default used if null)
  29.      */
  30.     public function __construct(KernelInterface $kernel$cacheDir null)
  31.     {
  32.         $this->kernel $kernel;
  33.         $this->cacheDir $cacheDir;
  34.         parent::__construct($kernel$this->createStore(), $this->createSurrogate(), array_merge(array('debug' => $kernel->isDebug()), $this->getOptions()));
  35.     }
  36.     /**
  37.      * Forwards the Request to the backend and returns the Response.
  38.      *
  39.      * @param Request  $request A Request instance
  40.      * @param bool     $raw     Whether to catch exceptions or not
  41.      * @param Response $entry   A Response instance (the stale entry if present, null otherwise)
  42.      *
  43.      * @return Response A Response instance
  44.      */
  45.     protected function forward(Request $request$raw falseResponse $entry null)
  46.     {
  47.         $this->getKernel()->boot();
  48.         $this->getKernel()->getContainer()->set('cache'$this);
  49.         return parent::forward($request$raw$entry);
  50.     }
  51.     /**
  52.      * Returns an array of options to customize the Cache configuration.
  53.      *
  54.      * @return array An array of options
  55.      */
  56.     protected function getOptions()
  57.     {
  58.         return array();
  59.     }
  60.     protected function createSurrogate()
  61.     {
  62.         return new Esi();
  63.     }
  64.     protected function createStore()
  65.     {
  66.         return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
  67.     }
  68. }