class Session

Session.

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

@api

Hierarchy

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

Expanded class hierarchy of Session

3 files declare their use of Session
NullSessionHandlerTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NullSessionHandlerTest.php
RequestTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/RequestTest.php
SessionTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
6 string references to 'Session'
language_language_negotiation_info in drupal/core/modules/language/language.module
Implements hook_language_negotiation_info().
SessionHttpsTest::getInfo in drupal/core/modules/system/lib/Drupal/system/Tests/Session/SessionHttpsTest.php
SessionTest::getInfo in drupal/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php
SessionTest::sessionReset in drupal/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php
Reset the cookie file so that it refers to the specified user.
SessionTest::testDataPersistence in drupal/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php
Test data persistence via the session_test module callbacks. Also tests drupal_session_count() since session data is already generated here.

... See full list

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Session.php, line 30

Namespace

Symfony\Component\HttpFoundation\Session
View source
class Session implements SessionInterface, \IteratorAggregate, \Countable {

  /**
   * Storage driver.
   *
   * @var SessionStorageInterface
   */
  protected $storage;

  /**
   * @var string
   */
  private $flashName;

  /**
   * @var string
   */
  private $attributeName;

  /**
   * Constructor.
   *
   * @param SessionStorageInterface $storage    A SessionStorageInterface instance.
   * @param AttributeBagInterface   $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
   * @param FlashBagInterface       $flashes    A FlashBagInterface instance (defaults null for default FlashBag)
   */
  public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) {
    $this->storage = $storage ?: new NativeSessionStorage();
    $attributes = $attributes ?: new AttributeBag();
    $this->attributeName = $attributes
      ->getName();
    $this
      ->registerBag($attributes);
    $flashes = $flashes ?: new FlashBag();
    $this->flashName = $flashes
      ->getName();
    $this
      ->registerBag($flashes);
  }

  /**
   * {@inheritdoc}
   */
  public function start() {
    return $this->storage
      ->start();
  }

  /**
   * {@inheritdoc}
   */
  public function has($name) {
    return $this->storage
      ->getBag($this->attributeName)
      ->has($name);
  }

  /**
   * {@inheritdoc}
   */
  public function get($name, $default = null) {
    return $this->storage
      ->getBag($this->attributeName)
      ->get($name, $default);
  }

  /**
   * {@inheritdoc}
   */
  public function set($name, $value) {
    $this->storage
      ->getBag($this->attributeName)
      ->set($name, $value);
  }

  /**
   * {@inheritdoc}
   */
  public function all() {
    return $this->storage
      ->getBag($this->attributeName)
      ->all();
  }

  /**
   * {@inheritdoc}
   */
  public function replace(array $attributes) {
    $this->storage
      ->getBag($this->attributeName)
      ->replace($attributes);
  }

  /**
   * {@inheritdoc}
   */
  public function remove($name) {
    return $this->storage
      ->getBag($this->attributeName)
      ->remove($name);
  }

  /**
   * {@inheritdoc}
   */
  public function clear() {
    $this->storage
      ->getBag($this->attributeName)
      ->clear();
  }

  /**
   * {@inheritdoc}
   */
  public function isStarted() {
    return $this->storage
      ->isStarted();
  }

  /**
   * Returns an iterator for attributes.
   *
   * @return \ArrayIterator An \ArrayIterator instance
   */
  public function getIterator() {
    return new \ArrayIterator($this->storage
      ->getBag($this->attributeName)
      ->all());
  }

  /**
   * Returns the number of attributes.
   *
   * @return int The number of attributes
   */
  public function count() {
    return count($this->storage
      ->getBag($this->attributeName)
      ->all());
  }

  /**
   * {@inheritdoc}
   */
  public function invalidate($lifetime = null) {
    $this->storage
      ->clear();
    return $this
      ->migrate(true, $lifetime);
  }

  /**
   * {@inheritdoc}
   */
  public function migrate($destroy = false, $lifetime = null) {
    return $this->storage
      ->regenerate($destroy, $lifetime);
  }

  /**
   * {@inheritdoc}
   */
  public function save() {
    $this->storage
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function getId() {
    return $this->storage
      ->getId();
  }

  /**
   * {@inheritdoc}
   */
  public function setId($id) {
    $this->storage
      ->setId($id);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return $this->storage
      ->getName();
  }

  /**
   * {@inheritdoc}
   */
  public function setName($name) {
    $this->storage
      ->setName($name);
  }

  /**
   * {@inheritdoc}
   */
  public function getMetadataBag() {
    return $this->storage
      ->getMetadataBag();
  }

  /**
   * {@inheritdoc}
   */
  public function registerBag(SessionBagInterface $bag) {
    $this->storage
      ->registerBag($bag);
  }

  /**
   * {@inheritdoc}
   */
  public function getBag($name) {
    return $this->storage
      ->getBag($name);
  }

  /**
   * Gets the flashbag interface.
   *
   * @return FlashBagInterface
   */
  public function getFlashBag() {
    return $this
      ->getBag($this->flashName);
  }

  // the following methods are kept for compatibility with Symfony 2.0 (they will be removed for Symfony 2.3)

  /**
   * @return array
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function getFlashes() {
    $all = $this
      ->getBag($this->flashName)
      ->all();
    $return = array();
    if ($all) {
      foreach ($all as $name => $array) {
        if (is_numeric(key($array))) {
          $return[$name] = reset($array);
        }
        else {
          $return[$name] = $array;
        }
      }
    }
    return $return;
  }

  /**
   * @param array $values
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function setFlashes($values) {
    foreach ($values as $name => $value) {
      $this
        ->getBag($this->flashName)
        ->set($name, $value);
    }
  }

  /**
   * @param string $name
   * @param string $default
   *
   * @return string
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function getFlash($name, $default = null) {
    $return = $this
      ->getBag($this->flashName)
      ->get($name);
    return empty($return) ? $default : reset($return);
  }

  /**
   * @param string $name
   * @param string $value
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function setFlash($name, $value) {
    $this
      ->getBag($this->flashName)
      ->set($name, $value);
  }

  /**
   * @param string $name
   *
   * @return Boolean
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function hasFlash($name) {
    return $this
      ->getBag($this->flashName)
      ->has($name);
  }

  /**
   * @param string $name
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function removeFlash($name) {
    $this
      ->getBag($this->flashName)
      ->get($name);
  }

  /**
   * @return array
   *
   * @deprecated since 2.1, will be removed from 2.3
   */
  public function clearFlashes() {
    return $this
      ->getBag($this->flashName)
      ->clear();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Session::$attributeName private property
Session::$flashName private property
Session::$storage protected property Storage driver.
Session::all public function Returns attributes. Overrides SessionInterface::all
Session::clear public function Clears all attributes. Overrides SessionInterface::clear
Session::clearFlashes Deprecated public function
Session::count public function Returns the number of attributes.
Session::get public function Returns an attribute. Overrides SessionInterface::get
Session::getBag public function Gets a bag instance by name. Overrides SessionInterface::getBag
Session::getFlash Deprecated public function
Session::getFlashBag public function Gets the flashbag interface.
Session::getFlashes Deprecated public function
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::has public function Checks if an attribute is defined. Overrides SessionInterface::has
Session::hasFlash Deprecated public function
Session::invalidate public function Invalidates the current session. Overrides SessionInterface::invalidate
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::removeFlash Deprecated public function
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::setFlash Deprecated public function
Session::setFlashes Deprecated public function
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 Constructor.