Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Session/MetadataBag.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Session; | |
4 | |
5 use Drupal\Core\Site\Settings; | |
6 use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag as SymfonyMetadataBag; | |
7 | |
8 /** | |
9 * Provides a container for application specific session metadata. | |
10 */ | |
11 class MetadataBag extends SymfonyMetadataBag { | |
12 | |
13 /** | |
14 * The key used to store the CSRF token seed in the session. | |
15 */ | |
16 const CSRF_TOKEN_SEED = 's'; | |
17 | |
18 /** | |
19 * Constructs a new metadata bag instance. | |
20 * | |
21 * @param \Drupal\Core\Site\Settings $settings | |
22 * The settings instance. | |
23 */ | |
24 public function __construct(Settings $settings) { | |
25 $update_threshold = $settings->get('session_write_interval', 180); | |
26 parent::__construct('_sf2_meta', $update_threshold); | |
27 } | |
28 | |
29 /** | |
30 * Set the CSRF token seed. | |
31 * | |
32 * @param string $csrf_token_seed | |
33 * The per-session CSRF token seed. | |
34 */ | |
35 public function setCsrfTokenSeed($csrf_token_seed) { | |
36 $this->meta[static::CSRF_TOKEN_SEED] = $csrf_token_seed; | |
37 } | |
38 | |
39 /** | |
40 * Get the CSRF token seed. | |
41 * | |
42 * @return string|null | |
43 * The per-session CSRF token seed or null when no value is set. | |
44 */ | |
45 public function getCsrfTokenSeed() { | |
46 if (isset($this->meta[static::CSRF_TOKEN_SEED])) { | |
47 return $this->meta[static::CSRF_TOKEN_SEED]; | |
48 } | |
49 } | |
50 | |
51 /** | |
52 * Clear the CSRF token seed. | |
53 */ | |
54 public function clearCsrfTokenSeed() { | |
55 unset($this->meta[static::CSRF_TOKEN_SEED]); | |
56 } | |
57 | |
58 } |