ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Collection.php
Go to the documentation of this file.
1<?php
9namespace Slim;
10
11use ArrayIterator;
13
22{
28 protected $data = [];
29
35 public function __construct(array $items = [])
36 {
37 $this->replace($items);
38 }
39
40 /********************************************************************************
41 * Collection interface
42 *******************************************************************************/
43
50 public function set($key, $value)
51 {
52 $this->data[$key] = $value;
53 }
54
63 public function get($key, $default = null)
64 {
65 return $this->has($key) ? $this->data[$key] : $default;
66 }
67
73 public function replace(array $items)
74 {
75 foreach ($items as $key => $value) {
76 $this->set($key, $value);
77 }
78 }
79
85 public function all()
86 {
87 return $this->data;
88 }
89
95 public function keys()
96 {
97 return array_keys($this->data);
98 }
99
107 public function has($key)
108 {
109 return array_key_exists($key, $this->data);
110 }
111
117 public function remove($key)
118 {
119 unset($this->data[$key]);
120 }
121
125 public function clear()
126 {
127 $this->data = [];
128 }
129
130 /********************************************************************************
131 * ArrayAccess interface
132 *******************************************************************************/
133
141 public function offsetExists($key)
142 {
143 return $this->has($key);
144 }
145
153 public function offsetGet($key)
154 {
155 return $this->get($key);
156 }
157
164 public function offsetSet($key, $value)
165 {
166 $this->set($key, $value);
167 }
168
174 public function offsetUnset($key)
175 {
176 $this->remove($key);
177 }
178
184 public function count()
185 {
186 return count($this->data);
187 }
188
189 /********************************************************************************
190 * IteratorAggregate interface
191 *******************************************************************************/
192
198 public function getIterator()
199 {
200 return new ArrayIterator($this->data);
201 }
202}
$default
Definition: build.php:20
An exception for terminatinating execution or to throw for unit testing.
Collection.
Definition: Collection.php:22
replace(array $items)
Add item to collection, replacing existing items with the same data key.
Definition: Collection.php:73
count()
Get number of items in collection.
Definition: Collection.php:184
keys()
Get collection keys.
Definition: Collection.php:95
clear()
Remove all items from collection.
Definition: Collection.php:125
all()
Get all items in collection.
Definition: Collection.php:85
offsetExists($key)
Does this collection have a given key?
Definition: Collection.php:141
offsetUnset($key)
Remove item from collection.
Definition: Collection.php:174
getIterator()
Get collection iterator.
Definition: Collection.php:198
offsetGet($key)
Get collection item for key.
Definition: Collection.php:153
has($key)
Does this collection have a given key?
Definition: Collection.php:107
__construct(array $items=[])
Create new collection.
Definition: Collection.php:35
offsetSet($key, $value)
Set collection item.
Definition: Collection.php:164
$key
Definition: croninfo.php:18
Slim Framework (https://slimframework.com)
Definition: App.php:9
$this data['403_header']
$data
Definition: bench.php:6