You are here

class FlashBag in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Session/Flash/FlashBag.php \Symfony\Component\HttpFoundation\Session\Flash\FlashBag

FlashBag flash message container.

\IteratorAggregate implementation is deprecated and will be removed in 3.0.

@author Drak <drak@zikula.org>

Hierarchy

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

Expanded class hierarchy of FlashBag

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

... See full list

1 string reference to 'FlashBag'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses FlashBag
session.flash_bag in core/core.services.yml
Symfony\Component\HttpFoundation\Session\Flash\FlashBag

File

vendor/symfony/http-foundation/Session/Flash/FlashBag.php, line 21

Namespace

Symfony\Component\HttpFoundation\Session\Flash
View source
class FlashBag implements FlashBagInterface, \IteratorAggregate {
  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.
   *
   * @deprecated since version 2.4, to be removed in 3.0.
   *
   * @return \ArrayIterator An \ArrayIterator instance
   */
  public function getIterator() {
    @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
    return new \ArrayIterator($this
      ->all());
  }

}

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::get public function Gets and clears flash from the stack. Overrides FlashBagInterface::get
FlashBag::getIterator Deprecated 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 messages 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.