summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/PageCache/RequestPolicyInterface.php
blob: 3a4ef212795af1b0a6c6068af087effe2659a1b4 (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
43
44
45
46
47
48
49
50
51
52
53
54
<?php

/**
 * @file
 * Contains \Drupal\Core\PageCache\RequestPolicyInterface.
 */

namespace Drupal\Core\PageCache;

use Symfony\Component\HttpFoundation\Request;

/**
 * Defines the interface for request policy implementations.
 *
 * The request policy is evaluated in order to determine whether delivery of a
 * cached page should be attempted. The caller should do so if static::ALLOW is
 * returned from the check() method.
 */
interface RequestPolicyInterface {

  /**
   * Allow delivery of cached pages.
   */
  const ALLOW = 'allow';

  /**
   * Deny delivery of cached pages.
   */
  const DENY = 'deny';

  /**
   * Determines whether delivery of a cached page should be attempted.
   *
   * Note that the request-policy check runs very early. In particular it is
   * not possible to determine the logged in user. Also the current route match
   * is not yet present when the check runs. Therefore, request-policy checks
   * need to be designed in a way such that they do not depend on any other
   * service and only take in account the information present on the incoming
   * request.
   *
   * When matching against the request path, special attention is needed to
   * support path prefixes which are often used on multilingual sites.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The incoming request object.
   *
   * @return string|NULL
   *   One of static::ALLOW, static::DENY or NULL. Calling code may attempt to
   *   deliver a cached page if static::ALLOW is returned. Returns NULL if the
   *   policy is not specified for the given request.
   */
  public function check(Request $request);

}