KillSwitch.php 741 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Drupal\Core\PageCache\ResponsePolicy;
  3. use Drupal\Core\PageCache\ResponsePolicyInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. /**
  7. * A policy evaluating to static::DENY when the kill switch was triggered.
  8. */
  9. class KillSwitch implements ResponsePolicyInterface {
  10. /**
  11. * A flag indicating whether the kill switch was triggered.
  12. *
  13. * @var bool
  14. */
  15. protected $kill = FALSE;
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function check(Response $response, Request $request) {
  20. if ($this->kill) {
  21. return static::DENY;
  22. }
  23. }
  24. /**
  25. * Deny any page caching on the current request.
  26. */
  27. public function trigger() {
  28. $this->kill = TRUE;
  29. }
  30. }