RequestPolicyInterface.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Drupal\Core\PageCache;
  3. use Symfony\Component\HttpFoundation\Request;
  4. /**
  5. * Defines the interface for request policy implementations.
  6. *
  7. * The request policy is evaluated in order to determine whether delivery of a
  8. * cached page should be attempted. The caller should do so if static::ALLOW is
  9. * returned from the check() method.
  10. */
  11. interface RequestPolicyInterface {
  12. /**
  13. * Allow delivery of cached pages.
  14. */
  15. const ALLOW = 'allow';
  16. /**
  17. * Deny delivery of cached pages.
  18. */
  19. const DENY = 'deny';
  20. /**
  21. * Determines whether delivery of a cached page should be attempted.
  22. *
  23. * Note that the request-policy check runs very early. In particular it is
  24. * not possible to determine the logged in user. Also the current route match
  25. * is not yet present when the check runs. Therefore, request-policy checks
  26. * need to be designed in a way such that they do not depend on any other
  27. * service and only take in account the information present on the incoming
  28. * request.
  29. *
  30. * When matching against the request path, special attention is needed to
  31. * support path prefixes which are often used on multilingual sites.
  32. *
  33. * @param \Symfony\Component\HttpFoundation\Request $request
  34. * The incoming request object.
  35. *
  36. * @return string|null
  37. * One of static::ALLOW, static::DENY or NULL. Calling code may attempt to
  38. * deliver a cached page if static::ALLOW is returned. Returns NULL if the
  39. * policy is not specified for the given request.
  40. */
  41. public function check(Request $request);
  42. }