summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php')
-rw-r--r--core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php b/core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php
new file mode 100644
index 0000000..62ecc45
--- /dev/null
+++ b/core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\PageCache\ResponsePolicy\KillSwitch.
+ */
+
+namespace Drupal\Core\PageCache\ResponsePolicy;
+
+use Drupal\Core\PageCache\ResponsePolicyInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * A policy evaluating to static::DENY when the kill switch was triggered.
+ */
+class KillSwitch implements ResponsePolicyInterface {
+
+ /**
+ * A flag indicating whether the kill switch was triggered.
+ *
+ * @var bool
+ */
+ protected $kill = FALSE;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function check(Response $response, Request $request) {
+ if ($this->kill) {
+ return static::DENY;
+ }
+ }
+
+ /**
+ * Deny any page caching on the current request.
+ */
+ public function trigger() {
+ $this->kill = TRUE;
+ }
+
+}