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