4 * Contains \Drupal\bootstrap\Utility\StorageItem.
7 namespace Drupal\bootstrap\Utility;
9 use Drupal\Core\KeyValueStore\MemoryStorage;
14 * This is essentially the same object as Storage. The only exception is
15 * delegating any data changes to the primary Storage object this
16 * StorageItem object lives in.
18 * This storage object can be used in `foreach` loops.
22 * @see \Drupal\bootstrap\Utility\Storage
24 class StorageItem extends MemoryStorage implements \Iterator {
27 * Flag determining whether or not object has been initialized yet.
31 protected $initialized = FALSE;
34 * The \Drupal\bootstrap\Storage instance this item belongs to.
36 * @var \Drupal\bootstrap\Utility\Storage
43 public function __construct($data, Storage $storage) {
44 $this->storage = $storage;
45 $this->setMultiple($data);
46 $this->initialized = TRUE;
50 * Notifies the main Storage object that data has changed.
52 public function changed() {
53 if ($this->initialized) {
54 $this->storage->changed();
61 public function current() {
62 return current($this->data);
68 public function delete($key) {
76 public function deleteMultiple(array $keys) {
77 parent::deleteMultiple($keys);
84 public function deleteAll() {
90 * Determines if the cache is empty.
95 public function isEmpty() {
96 return empty($this->data);
102 public function key() {
103 return key($this->data);
109 public function next() {
110 return next($this->data);
116 public function rename($key, $new_key) {
117 parent::rename($key, $new_key);
124 public function rewind() {
125 return reset($this->data);
131 public function set($key, $value) {
132 parent::set($key, $value);
139 public function setIfNotExists($key, $value) {
140 if (!isset($this->data[$key])) {
141 $this->data[$key] = $value;
151 public function setMultiple(array $data) {
152 parent::setMultiple($data);
159 public function valid() {
160 return key($this->data) !== NULL;