SurrogateInterface.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. public function getName(): string;
  19. /**
  20. * Returns a new cache strategy instance.
  21. */
  22. public function createCacheStrategy(): ResponseCacheStrategyInterface;
  23. /**
  24. * Checks that at least one surrogate has Surrogate capability.
  25. */
  26. public function hasSurrogateCapability(Request $request): bool;
  27. /**
  28. * Adds Surrogate-capability to the given Request.
  29. */
  30. public function addSurrogateCapability(Request $request): void;
  31. /**
  32. * Adds HTTP headers to specify that the Response needs to be parsed for Surrogate.
  33. *
  34. * This method only adds an Surrogate HTTP header if the Response has some Surrogate tags.
  35. */
  36. public function addSurrogateControl(Response $response): void;
  37. /**
  38. * Checks that the Response needs to be parsed for Surrogate tags.
  39. */
  40. public function needsParsing(Response $response): bool;
  41. /**
  42. * Renders a Surrogate tag.
  43. *
  44. * @param string|null $alt An alternate URI
  45. * @param string $comment A comment to add as an esi:include tag
  46. */
  47. public function renderIncludeTag(string $uri, ?string $alt = null, bool $ignoreErrors = true, string $comment = ''): string;
  48. /**
  49. * Replaces a Response Surrogate tags with the included resource content.
  50. */
  51. public function process(Request $request, Response $response): Response;
  52. /**
  53. * Handles a Surrogate from the cache.
  54. *
  55. * @param string $alt An alternative URI
  56. *
  57. * @throws \RuntimeException
  58. * @throws \Exception
  59. */
  60. public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string;
  61. }