3 namespace Drupal\Core\Session;
5 use Drupal\Core\Site\Settings;
6 use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag as SymfonyMetadataBag;
9 * Provides a container for application specific session metadata.
11 class MetadataBag extends SymfonyMetadataBag {
14 * The key used to store the CSRF token seed in the session.
16 const CSRF_TOKEN_SEED = 's';
19 * Constructs a new metadata bag instance.
21 * @param \Drupal\Core\Site\Settings $settings
22 * The settings instance.
24 public function __construct(Settings $settings) {
25 $update_threshold = $settings->get('session_write_interval', 180);
26 parent::__construct('_sf2_meta', $update_threshold);
30 * Set the CSRF token seed.
32 * @param string $csrf_token_seed
33 * The per-session CSRF token seed.
35 public function setCsrfTokenSeed($csrf_token_seed) {
36 $this->meta[static::CSRF_TOKEN_SEED] = $csrf_token_seed;
40 * Get the CSRF token seed.
43 * The per-session CSRF token seed or null when no value is set.
45 public function getCsrfTokenSeed() {
46 if (isset($this->meta[static::CSRF_TOKEN_SEED])) {
47 return $this->meta[static::CSRF_TOKEN_SEED];
52 * Clear the CSRF token seed.
54 public function clearCsrfTokenSeed() {
55 unset($this->meta[static::CSRF_TOKEN_SEED]);