Cache.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\Cache;
  3. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4. use Symfony\Component\HttpKernel\Cache\Cache as BaseCache;
  5. use Symfony\Component\HttpKernel\Cache\Esi;
  6. use Symfony\Component\HttpKernel\Cache\Store;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. /*
  10. * This file is part of the Symfony package.
  11. *
  12. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  13. *
  14. * For the full copyright and license information, please view the LICENSE
  15. * file that was distributed with this source code.
  16. */
  17. /**
  18. *
  19. * @author Fabien Potencier <fabien.potencier@symfony-project.org>
  20. */
  21. abstract class Cache extends BaseCache
  22. {
  23. /**
  24. * Constructor.
  25. *
  26. * @param HttpKernelInterface $kernel An HttpKernelInterface instance
  27. */
  28. public function __construct(HttpKernelInterface $kernel)
  29. {
  30. $this->store = new Store($kernel->getCacheDir().'/http_cache');
  31. $esi = new Esi();
  32. parent::__construct($kernel, $this->store, $esi, array_merge(array('debug' => $kernel->isDebug()), $this->getOptions()));
  33. }
  34. /**
  35. * Forwards the Request to the backend and returns the Response.
  36. *
  37. * @param Requset $request A Request instance
  38. * @param Boolean $raw Whether to catch exceptions or not
  39. * @param Response $response A Response instance (the stale entry if present, null otherwise)
  40. *
  41. * @return Response A Response instance
  42. */
  43. protected function forward(Request $request, $raw = false, Response $entry = null)
  44. {
  45. if (!$this->kernel->isBooted()) {
  46. $this->kernel->boot();
  47. }
  48. $this->kernel->getContainer()->set('cache', $this);
  49. $this->kernel->getContainer()->set('esi', $this->esi);
  50. return parent::forward($request, $raw, $entry);
  51. }
  52. /**
  53. * Returns an array of options to customize the Cache configuration.
  54. *
  55. * @return array An array of options
  56. */
  57. protected function getOptions()
  58. {
  59. return array();
  60. }
  61. }