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

Breadcrumb

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

class Session

Same name in this branch
  1. 11.1.x vendor/lullabot/php-webdriver/lib/WebDriver/Session.php \WebDriver\Session
  2. 11.1.x vendor/lullabot/php-webdriver/lib/WebDriver/Storage/Session.php \WebDriver\Storage\Session
  3. 11.1.x vendor/behat/mink/src/Session.php \Behat\Mink\Session
  4. 11.1.x core/lib/Drupal/Core/StackMiddleware/Session.php \Drupal\Core\StackMiddleware\Session

@author Fabien Potencier <fabien@symfony.com> @author Drak <drak@zikula.org>

@implements \IteratorAggregate<string, mixed>

Hierarchy

  • class \Symfony\Component\HttpFoundation\Session\Session implements \Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface, \Symfony\Component\HttpFoundation\Session\IteratorAggregate, \Symfony\Component\HttpFoundation\Session\Countable

Expanded class hierarchy of Session

5 files declare their use of Session
AbstractSessionListener.php in vendor/symfony/http-kernel/EventListener/AbstractSessionListener.php
DrupalKernel.php in core/lib/Drupal/Core/DrupalKernel.php
FunctionalTestSetupTrait.php in core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
ProfilerListener.php in vendor/symfony/http-kernel/EventListener/ProfilerListener.php
SessionWorkspaceNegotiator.php in core/modules/workspaces/src/Negotiator/SessionWorkspaceNegotiator.php
24 string references to 'Session'
authorize.php in core/authorize.php
Administrative script for running authorized file operations.
default.services.yml in sites/default/default.services.yml
sites/default/default.services.yml
default.services.yml in core/assets/scaffold/files/default.services.yml
core/assets/scaffold/files/default.services.yml
DrupalKernel::initializeContainer in core/lib/Drupal/Core/DrupalKernel.php
Initializes the service container.
DrupalKernel::resetContainer in core/lib/Drupal/Core/DrupalKernel.php
Force a container reset.

... See full list

File

vendor/symfony/http-foundation/Session/Session.php, line 33

Namespace

Symfony\Component\HttpFoundation\Session
View source
class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Countable {
    protected SessionStorageInterface $storage;
    private string $flashName;
    private string $attributeName;
    private array $data = [];
    private int $usageIndex = 0;
    private ?\Closure $usageReporter;
    public function __construct(?SessionStorageInterface $storage = null, ?AttributeBagInterface $attributes = null, ?FlashBagInterface $flashes = null, ?callable $usageReporter = null) {
        $this->storage = $storage ?? new NativeSessionStorage();
        $this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
        $attributes ??= new AttributeBag();
        $this->attributeName = $attributes->getName();
        $this->registerBag($attributes);
        $flashes ??= new FlashBag();
        $this->flashName = $flashes->getName();
        $this->registerBag($flashes);
    }
    public function start() : bool {
        return $this->storage
            ->start();
    }
    public function has(string $name) : bool {
        return $this->getAttributeBag()
            ->has($name);
    }
    public function get(string $name, mixed $default = null) : mixed {
        return $this->getAttributeBag()
            ->get($name, $default);
    }
    public function set(string $name, mixed $value) : void {
        $this->getAttributeBag()
            ->set($name, $value);
    }
    public function all() : array {
        return $this->getAttributeBag()
            ->all();
    }
    public function replace(array $attributes) : void {
        $this->getAttributeBag()
            ->replace($attributes);
    }
    public function remove(string $name) : mixed {
        return $this->getAttributeBag()
            ->remove($name);
    }
    public function clear() : void {
        $this->getAttributeBag()
            ->clear();
    }
    public function isStarted() : bool {
        return $this->storage
            ->isStarted();
    }
    
    /**
     * Returns an iterator for attributes.
     *
     * @return \ArrayIterator<string, mixed>
     */
    public function getIterator() : \ArrayIterator {
        return new \ArrayIterator($this->getAttributeBag()
            ->all());
    }
    
    /**
     * Returns the number of attributes.
     */
    public function count() : int {
        return \count($this->getAttributeBag()
            ->all());
    }
    public function &getUsageIndex() : int {
        return $this->usageIndex;
    }
    
    /**
     * @internal
     */
    public function isEmpty() : bool {
        if ($this->isStarted()) {
            ++$this->usageIndex;
            if ($this->usageReporter && 0 <= $this->usageIndex) {
                ($this->usageReporter)();
            }
        }
        foreach ($this->data as &$data) {
            if ($data) {
                return false;
            }
        }
        return true;
    }
    public function invalidate(?int $lifetime = null) : bool {
        $this->storage
            ->clear();
        return $this->migrate(true, $lifetime);
    }
    public function migrate(bool $destroy = false, ?int $lifetime = null) : bool {
        return $this->storage
            ->regenerate($destroy, $lifetime);
    }
    public function save() : void {
        $this->storage
            ->save();
    }
    public function getId() : string {
        return $this->storage
            ->getId();
    }
    public function setId(string $id) : void {
        if ($this->storage
            ->getId() !== $id) {
            $this->storage
                ->setId($id);
        }
    }
    public function getName() : string {
        return $this->storage
            ->getName();
    }
    public function setName(string $name) : void {
        $this->storage
            ->setName($name);
    }
    public function getMetadataBag() : MetadataBag {
        ++$this->usageIndex;
        if ($this->usageReporter && 0 <= $this->usageIndex) {
            ($this->usageReporter)();
        }
        return $this->storage
            ->getMetadataBag();
    }
    public function registerBag(SessionBagInterface $bag) : void {
        $this->storage
            ->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex, $this->usageReporter));
    }
    public function getBag(string $name) : SessionBagInterface {
        $bag = $this->storage
            ->getBag($name);
        return method_exists($bag, 'getBag') ? $bag->getBag() : $bag;
    }
    
    /**
     * Gets the flashbag interface.
     */
    public function getFlashBag() : FlashBagInterface {
        return $this->getBag($this->flashName);
    }
    
    /**
     * Gets the attributebag interface.
     *
     * Note that this method was added to help with IDE autocompletion.
     */
    private function getAttributeBag() : AttributeBagInterface {
        return $this->getBag($this->attributeName);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Session::$attributeName private property
Session::$data private property
Session::$flashName private property
Session::$storage protected property
Session::$usageIndex private property
Session::$usageReporter private property
Session::all public function Returns attributes. Overrides SessionInterface::all
Session::clear public function Clears all attributes. Overrides SessionInterface::clear
Session::count public function Returns the number of attributes.
Session::get public function Returns an attribute. Overrides SessionInterface::get
Session::getAttributeBag private function Gets the attributebag interface.
Session::getBag public function Gets a bag instance by name. Overrides SessionInterface::getBag
Session::getFlashBag public function Gets the flashbag interface. Overrides FlashBagAwareSessionInterface::getFlashBag
Session::getId public function Returns the session ID. Overrides SessionInterface::getId
Session::getIterator public function Returns an iterator for attributes.
Session::getMetadataBag public function Gets session meta. Overrides SessionInterface::getMetadataBag
Session::getName public function Returns the session name. Overrides SessionInterface::getName
Session::getUsageIndex public function
Session::has public function Checks if an attribute is defined. Overrides SessionInterface::has
Session::invalidate public function Invalidates the current session. Overrides SessionInterface::invalidate
Session::isEmpty public function @internal
Session::isStarted public function Checks if the session was started. Overrides SessionInterface::isStarted
Session::migrate public function Migrates the current session to a new session id while maintaining all
session attributes.
Overrides SessionInterface::migrate
Session::registerBag public function Registers a SessionBagInterface with the session. Overrides SessionInterface::registerBag
Session::remove public function Removes an attribute. Overrides SessionInterface::remove
Session::replace public function Sets attributes. Overrides SessionInterface::replace
Session::save public function Force the session to be saved and closed. Overrides SessionInterface::save
Session::set public function Sets an attribute. Overrides SessionInterface::set
Session::setId public function Sets the session ID. Overrides SessionInterface::setId
Session::setName public function Sets the session name. Overrides SessionInterface::setName
Session::start public function Starts the session storage. Overrides SessionInterface::start
Session::__construct public function

API Navigation

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