class FlashBag

FlashBag flash message container.

@author Drak <drak@zikula.org>

Hierarchy

  • class \Symfony\Component\HttpFoundation\Session\Flash\FlashBag implements \Symfony\Component\HttpFoundation\Session\Flash\IteratorAggregate, \Symfony\Component\HttpFoundation\Session\Flash\Countable, FlashBagInterface

Expanded class hierarchy of FlashBag

6 files declare their use of FlashBag
FlashBagTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/Flash/FlashBagTest.php
MockArraySessionStorageTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php
MockFileSessionStorageTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockFileSessionStorageTest.php
NativeSessionStorageTest.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php
Session.php in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Session.php

... See full list

File

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

Namespace

Symfony\Component\HttpFoundation\Session\Flash
View source
class FlashBag implements FlashBagInterface, \IteratorAggregate, \Countable {
  private $name = 'flashes';

  /**
   * Flash messages.
   *
   * @var array
   */
  private $flashes = array();

  /**
   * The storage key for flashes in the session
   *
   * @var string
   */
  private $storageKey;

  /**
   * Constructor.
   *
   * @param string $storageKey The key used to store flashes in the session.
   */
  public function __construct($storageKey = '_sf2_flashes') {
    $this->storageKey = $storageKey;
  }

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

  /**
   * {@inheritdoc}
   */
  public function initialize(array &$flashes) {
    $this->flashes =& $flashes;
  }

  /**
   * {@inheritdoc}
   */
  public function add($type, $message) {
    $this->flashes[$type][] = $message;
  }

  /**
   * {@inheritdoc}
   */
  public function peek($type, array $default = array()) {
    return $this
      ->has($type) ? $this->flashes[$type] : $default;
  }

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

  /**
   * {@inheritdoc}
   */
  public function get($type, array $default = array()) {
    if (!$this
      ->has($type)) {
      return $default;
    }
    $return = $this->flashes[$type];
    unset($this->flashes[$type]);
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  public function all() {
    $return = $this
      ->peekAll();
    $this->flashes = array();
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  public function set($type, $messages) {
    $this->flashes[$type] = (array) $messages;
  }

  /**
   * {@inheritdoc}
   */
  public function setAll(array $messages) {
    $this->flashes = $messages;
  }

  /**
   * {@inheritdoc}
   */
  public function has($type) {
    return array_key_exists($type, $this->flashes) && $this->flashes[$type];
  }

  /**
   * {@inheritdoc}
   */
  public function keys() {
    return array_keys($this->flashes);
  }

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

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

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

  /**
   * Returns the number of flashes.
   *
   * @return int The number of flashes
   */
  public function count() {
    return count($this->flashes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlashBag::$flashes private property Flash messages.
FlashBag::$name private property
FlashBag::$storageKey private property The storage key for flashes in the session
FlashBag::add public function Adds a flash message for type. Overrides FlashBagInterface::add
FlashBag::all public function Gets and clears flashes from the stack. Overrides FlashBagInterface::all
FlashBag::clear public function Clears out data from bag. Overrides SessionBagInterface::clear
FlashBag::count public function Returns the number of flashes.
FlashBag::get public function Gets and clears flash from the stack. Overrides FlashBagInterface::get
FlashBag::getIterator public function Returns an iterator for flashes.
FlashBag::getName public function Gets this bag's name Overrides SessionBagInterface::getName
FlashBag::getStorageKey public function Gets the storage key for this bag. Overrides SessionBagInterface::getStorageKey
FlashBag::has public function Has flash messages for a given type? Overrides FlashBagInterface::has
FlashBag::initialize public function Initializes the Bag Overrides SessionBagInterface::initialize
FlashBag::keys public function Returns a list of all defined types. Overrides FlashBagInterface::keys
FlashBag::peek public function Gets flash message for a given type. Overrides FlashBagInterface::peek
FlashBag::peekAll public function Gets all flash messages. Overrides FlashBagInterface::peekAll
FlashBag::set public function Registers a message for a given type. Overrides FlashBagInterface::set
FlashBag::setAll public function Sets all flash messages. Overrides FlashBagInterface::setAll
FlashBag::setName public function
FlashBag::__construct public function Constructor.