summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/PageCache/ResponsePolicy/KillSwitch.php
blob: 62ecc45db14b0a3d90c954ab71a19e9a4335bfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
  }

}