SurrogateInterface.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\Component\HttpKernel\HttpCache;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. interface SurrogateInterface
  14. {
  15. /**
  16. * Returns surrogate name.
  17. *
  18. * @return string
  19. */
  20. public function getName();
  21. /**
  22. * Returns a new cache strategy instance.
  23. *
  24. * @return ResponseCacheStrategyInterface A ResponseCacheStrategyInterface instance
  25. */
  26. public function createCacheStrategy();
  27. /**
  28. * Checks that at least one surrogate has Surrogate capability.
  29. *
  30. * @param Request $request A Request instance
  31. *
  32. * @return bool true if one surrogate has Surrogate capability, false otherwise
  33. */
  34. public function hasSurrogateCapability(Request $request);
  35. /**
  36. * Adds Surrogate-capability to the given Request.
  37. *
  38. * @param Request $request A Request instance
  39. */
  40. public function addSurrogateCapability(Request $request);
  41. /**
  42. * Adds HTTP headers to specify that the Response needs to be parsed for Surrogate.
  43. *
  44. * This method only adds an Surrogate HTTP header if the Response has some Surrogate tags.
  45. *
  46. * @param Response $response A Response instance
  47. */
  48. public function addSurrogateControl(Response $response);
  49. /**
  50. * Checks that the Response needs to be parsed for Surrogate tags.
  51. *
  52. * @param Response $response A Response instance
  53. *
  54. * @return bool true if the Response needs to be parsed, false otherwise
  55. */
  56. public function needsParsing(Response $response);
  57. /**
  58. * Renders a Surrogate tag.
  59. *
  60. * @param string $uri A URI
  61. * @param string $alt An alternate URI
  62. * @param bool $ignoreErrors Whether to ignore errors or not
  63. * @param string $comment A comment to add as an esi:include tag
  64. *
  65. * @return string
  66. */
  67. public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = '');
  68. /**
  69. * Replaces a Response Surrogate tags with the included resource content.
  70. *
  71. * @param Request $request A Request instance
  72. * @param Response $response A Response instance
  73. *
  74. * @return Response
  75. */
  76. public function process(Request $request, Response $response);
  77. /**
  78. * Handles a Surrogate from the cache.
  79. *
  80. * @param HttpCache $cache An HttpCache instance
  81. * @param string $uri The main URI
  82. * @param string $alt An alternative URI
  83. * @param bool $ignoreErrors Whether to ignore errors or not
  84. *
  85. * @return string
  86. *
  87. * @throws \RuntimeException
  88. * @throws \Exception
  89. */
  90. public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors);
  91. }