SurrogateInterface.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * @return void
  31. */
  32. public function addSurrogateCapability(Request $request);
  33. /**
  34. * Adds HTTP headers to specify that the Response needs to be parsed for Surrogate.
  35. *
  36. * This method only adds an Surrogate HTTP header if the Response has some Surrogate tags.
  37. *
  38. * @return void
  39. */
  40. public function addSurrogateControl(Response $response);
  41. /**
  42. * Checks that the Response needs to be parsed for Surrogate tags.
  43. */
  44. public function needsParsing(Response $response): bool;
  45. /**
  46. * Renders a Surrogate tag.
  47. *
  48. * @param string|null $alt An alternate URI
  49. * @param string $comment A comment to add as an esi:include tag
  50. */
  51. public function renderIncludeTag(string $uri, ?string $alt = null, bool $ignoreErrors = true, string $comment = ''): string;
  52. /**
  53. * Replaces a Response Surrogate tags with the included resource content.
  54. */
  55. public function process(Request $request, Response $response): Response;
  56. /**
  57. * Handles a Surrogate from the cache.
  58. *
  59. * @param string $alt An alternative URI
  60. *
  61. * @throws \RuntimeException
  62. * @throws \Exception
  63. */
  64. public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string;
  65. }