Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MetadataBag.php

class MetadataBag

Same name in this branch
  1. 11.1.x vendor/symfony/http-foundation/Session/Storage/MetadataBag.php \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag

Provides a container for application specific session metadata.

Hierarchy

  • class \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag implements \Symfony\Component\HttpFoundation\Session\SessionBagInterface
    • class \Drupal\Core\Session\MetadataBag extends \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag

Expanded class hierarchy of MetadataBag

1 file declares its use of MetadataBag
CsrfTokenGenerator.php in core/lib/Drupal/Core/Access/CsrfTokenGenerator.php

File

core/lib/Drupal/Core/Session/MetadataBag.php, line 12

Namespace

Drupal\Core\Session
View source
class MetadataBag extends SymfonyMetadataBag {
    
    /**
     * The key used to store the CSRF token seed in the session.
     */
    const CSRF_TOKEN_SEED = 's';
    
    /**
     * Constructs a new metadata bag instance.
     *
     * @param \Drupal\Core\Site\Settings $settings
     *   The settings instance.
     */
    public function __construct(Settings $settings) {
        $update_threshold = $settings->get('session_write_interval', 180);
        parent::__construct('_sf2_meta', $update_threshold);
    }
    
    /**
     * Set the CSRF token seed.
     *
     * @param string $csrf_token_seed
     *   The per-session CSRF token seed.
     */
    public function setCsrfTokenSeed($csrf_token_seed) {
        $this->meta[static::CSRF_TOKEN_SEED] = $csrf_token_seed;
    }
    
    /**
     * Get the CSRF token seed.
     *
     * @return string|null
     *   The per-session CSRF token seed or null when no value is set.
     */
    public function getCsrfTokenSeed() {
        if (isset($this->meta[static::CSRF_TOKEN_SEED])) {
            return $this->meta[static::CSRF_TOKEN_SEED];
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function stampNew($lifetime = NULL) : void {
        parent::stampNew($lifetime);
        // Set the token seed immediately to avoid a race condition between two
        // simultaneous requests without a seed.
        $this->setCsrfTokenSeed(Crypt::randomBytesBase64());
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
MetadataBag::$lastUsed private property
MetadataBag::$meta protected property
MetadataBag::$name private property
MetadataBag::clear public function Clears out data from bag. Overrides SessionBagInterface::clear
MetadataBag::CREATED public constant
MetadataBag::CSRF_TOKEN_SEED constant The key used to store the CSRF token seed in the session.
MetadataBag::getCreated public function Gets the created timestamp metadata.
MetadataBag::getCsrfTokenSeed public function Get the CSRF token seed.
MetadataBag::getLastUsed public function Gets the last used metadata.
MetadataBag::getLifetime public function Gets the lifetime that the session cookie was set with.
MetadataBag::getName public function Gets this bag's name. Overrides SessionBagInterface::getName
MetadataBag::getStorageKey public function Gets the storage key for this bag. Overrides SessionBagInterface::getStorageKey
MetadataBag::initialize public function Initializes the Bag. Overrides SessionBagInterface::initialize
MetadataBag::LIFETIME public constant
MetadataBag::setCsrfTokenSeed public function Set the CSRF token seed.
MetadataBag::setName public function Sets name.
MetadataBag::stampCreated private function
MetadataBag::stampNew public function Stamps a new session's metadata. Overrides MetadataBag::stampNew
MetadataBag::UPDATED public constant
MetadataBag::__construct public function Constructs a new metadata bag instance. Overrides MetadataBag::__construct

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal