SurrogateInterface.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * @return bool true if one surrogate has Surrogate capability, false otherwise
  31. */
  32. public function hasSurrogateCapability(Request $request);
  33. /**
  34. * Adds Surrogate-capability to the given Request.
  35. */
  36. public function addSurrogateCapability(Request $request);
  37. /**
  38. * Adds HTTP headers to specify that the Response needs to be parsed for Surrogate.
  39. *
  40. * This method only adds an Surrogate HTTP header if the Response has some Surrogate tags.
  41. */
  42. public function addSurrogateControl(Response $response);
  43. /**
  44. * Checks that the Response needs to be parsed for Surrogate tags.
  45. *
  46. * @return bool true if the Response needs to be parsed, false otherwise
  47. */
  48. public function needsParsing(Response $response);
  49. /**
  50. * Renders a Surrogate tag.
  51. *
  52. * @param string $uri A URI
  53. * @param string $alt An alternate URI
  54. * @param bool $ignoreErrors Whether to ignore errors or not
  55. * @param string $comment A comment to add as an esi:include tag
  56. *
  57. * @return string
  58. */
  59. public function renderIncludeTag($uri, $alt = null, $ignoreErrors = true, $comment = '');
  60. /**
  61. * Replaces a Response Surrogate tags with the included resource content.
  62. *
  63. * @return Response
  64. */
  65. public function process(Request $request, Response $response);
  66. /**
  67. * Handles a Surrogate from the cache.
  68. *
  69. * @param HttpCache $cache An HttpCache instance
  70. * @param string $uri The main URI
  71. * @param string $alt An alternative URI
  72. * @param bool $ignoreErrors Whether to ignore errors or not
  73. *
  74. * @return string
  75. *
  76. * @throws \RuntimeException
  77. * @throws \Exception
  78. */
  79. public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors);
  80. }