You are here

class StorageItem in Express 8

Theme Storage Item.

This is essentially the same object as Storage. The only exception is delegating any data changes to the primary Storage object this StorageItem object lives in.

This storage object can be used in `foreach` loops.

Hierarchy

Expanded class hierarchy of StorageItem

See also

\Drupal\bootstrap\Utility\Storage

1 file declares its use of StorageItem
Theme.php in themes/contrib/bootstrap/src/Theme.php
Contains \Drupal\bootstrap.

File

themes/contrib/bootstrap/src/Utility/StorageItem.php, line 24
Contains \Drupal\bootstrap\Utility\StorageItem.

Namespace

Drupal\bootstrap\Utility
View source
class StorageItem extends MemoryStorage implements \Iterator {

  /**
   * Flag determining whether or not object has been initialized yet.
   *
   * @var bool
   */
  protected $initialized = FALSE;

  /**
   * The \Drupal\bootstrap\Storage instance this item belongs to.
   *
   * @var \Drupal\bootstrap\Utility\Storage
   */
  protected $storage;

  /**
   * {@inheritdoc}
   */
  public function __construct($data, Storage $storage) {
    $this->storage = $storage;
    $this
      ->setMultiple($data);
    $this->initialized = TRUE;
  }

  /**
   * Notifies the main Storage object that data has changed.
   */
  public function changed() {
    if ($this->initialized) {
      $this->storage
        ->changed();
    }
  }

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

  /**
   * {@inheritdoc}
   */
  public function delete($key) {
    parent::delete($key);
    $this
      ->changed();
  }

  /**
   * {@inheritdoc}
   */
  public function deleteMultiple(array $keys) {
    parent::deleteMultiple($keys);
    $this
      ->changed();
  }

  /**
   * {@inheritdoc}
   */
  public function deleteAll() {
    parent::deleteAll();
    $this
      ->changed();
  }

  /**
   * Determines if the cache is empty.
   *
   * @return bool
   *   TRUE or FALSE
   */
  public function isEmpty() {
    return empty($this->data);
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function rename($key, $new_key) {
    parent::rename($key, $new_key);
    $this
      ->changed();
  }

  /**
   * {@inheritdoc}
   */
  public function rewind() {
    return reset($this->data);
  }

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    parent::set($key, $value);
    $this
      ->changed();
  }

  /**
   * {@inheritdoc}
   */
  public function setIfNotExists($key, $value) {
    if (!isset($this->data[$key])) {
      $this->data[$key] = $value;
      $this
        ->changed();
      return TRUE;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function setMultiple(array $data) {
    parent::setMultiple($data);
    $this
      ->changed();
  }

  /**
   * {@inheritdoc}
   */
  public function valid() {
    return key($this->data) !== NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemoryStorage::$data protected property The actual storage of key-value pairs.
MemoryStorage::get public function Returns the stored value for a given key. Overrides StorageBase::get
MemoryStorage::getAll public function Returns all stored key/value pairs in the collection. Overrides KeyValueStoreInterface::getAll
MemoryStorage::getMultiple public function Returns the stored key/value pairs for a given set of keys. Overrides KeyValueStoreInterface::getMultiple
MemoryStorage::has public function Returns whether a given key exists in the store. Overrides KeyValueStoreInterface::has
StorageBase::$collection protected property The name of the collection holding key and value pairs.
StorageBase::getCollectionName public function Returns the name of this collection. Overrides KeyValueStoreInterface::getCollectionName
StorageItem::$initialized protected property Flag determining whether or not object has been initialized yet.
StorageItem::$storage protected property The \Drupal\bootstrap\Storage instance this item belongs to.
StorageItem::changed public function Notifies the main Storage object that data has changed.
StorageItem::current public function
StorageItem::delete public function Deletes an item from the key/value store. Overrides MemoryStorage::delete
StorageItem::deleteAll public function Deletes all items from the key/value store. Overrides MemoryStorage::deleteAll
StorageItem::deleteMultiple public function Deletes multiple items from the key/value store. Overrides MemoryStorage::deleteMultiple
StorageItem::isEmpty public function Determines if the cache is empty.
StorageItem::key public function
StorageItem::next public function
StorageItem::rename public function Renames a key. Overrides MemoryStorage::rename
StorageItem::rewind public function
StorageItem::set public function Saves a value for a given key. Overrides MemoryStorage::set
StorageItem::setIfNotExists public function Saves a value for a given key if it does not exist yet. Overrides MemoryStorage::setIfNotExists
StorageItem::setMultiple public function Saves key/value pairs. Overrides MemoryStorage::setMultiple
StorageItem::valid public function
StorageItem::__construct public function Overrides StorageBase::__construct