e29ae0bd032b0db29da5c75ff9cf103b400ce7cd
[yaffs-website] / web / core / lib / Drupal / Core / PageCache / RequestPolicy / NoSessionOpen.php
1 <?php
2
3 namespace Drupal\Core\PageCache\RequestPolicy;
4
5 use Drupal\Core\PageCache\RequestPolicyInterface;
6 use Drupal\Core\Session\SessionConfigurationInterface;
7 use Symfony\Component\HttpFoundation\Request;
8
9 /**
10  * A policy allowing delivery of cached pages when there is no session open.
11  *
12  * Do not serve cached pages to authenticated users, or to anonymous users when
13  * $_SESSION is non-empty. $_SESSION may contain status messages from a form
14  * submission, the contents of a shopping cart, or other user-specific content
15  * that should not be cached and displayed to other users.
16  */
17 class NoSessionOpen implements RequestPolicyInterface {
18
19   /**
20    * The session configuration.
21    *
22    * @var \Drupal\Core\Session\SessionConfigurationInterface
23    */
24   protected $sessionConfiguration;
25
26   /**
27    * Constructs a new page cache session policy.
28    *
29    * @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
30    *   The session configuration.
31    */
32   public function __construct(SessionConfigurationInterface $session_configuration) {
33     $this->sessionConfiguration = $session_configuration;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function check(Request $request) {
40     if (!$this->sessionConfiguration->hasSession($request)) {
41       return static::ALLOW;
42     }
43   }
44
45 }