1 | <?php |
||
39 | class Collection implements ArrayAccess, Countable, IteratorAggregate |
||
40 | { |
||
41 | /** |
||
42 | * The items contained in the collection. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $items = []; |
||
47 | |||
48 | /** |
||
49 | * Create a new collection. |
||
50 | * |
||
51 | * @param array $items |
||
52 | */ |
||
53 | public function __construct(array $items = []) |
||
54 | { |
||
55 | $this->items = $items; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Gets the value of a field from the Graph node. |
||
60 | * |
||
61 | * @param string $name The field to retrieve. |
||
62 | * @param mixed $default The default to return if the field doesn't exist. |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | public function getField($name, $default = null) |
||
67 | { |
||
68 | if (isset($this->items[$name])) { |
||
69 | return $this->items[$name]; |
||
70 | } |
||
71 | |||
72 | return $default; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Gets the value of the named property for this graph object. |
||
77 | * |
||
78 | * @param string $name The property to retrieve. |
||
79 | * @param mixed $default The default to return if the property doesn't exist. |
||
80 | * |
||
81 | * @return mixed |
||
82 | * |
||
83 | * @deprecated 5.0.0 getProperty() has been renamed to getField() |
||
84 | * @todo v6: Remove this method |
||
85 | */ |
||
86 | public function getProperty($name, $default = null) |
||
87 | { |
||
88 | return $this->getField($name, $default); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns a list of all fields set on the object. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function getFieldNames() |
||
100 | |||
101 | /** |
||
102 | * Returns a list of all properties set on the object. |
||
103 | * |
||
104 | * @return array |
||
105 | * |
||
106 | * @deprecated 5.0.0 getPropertyNames() has been renamed to getFieldNames() |
||
107 | * @todo v6: Remove this method |
||
108 | */ |
||
109 | public function getPropertyNames() |
||
113 | |||
114 | /** |
||
115 | * Get all of the items in the collection. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function all() |
||
123 | |||
124 | /** |
||
125 | * Get the collection of items as a plain array. |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function asArray() |
||
135 | |||
136 | /** |
||
137 | * Run a map over each of the items. |
||
138 | * |
||
139 | * @param \Closure $callback |
||
140 | * |
||
141 | * @return static |
||
142 | */ |
||
143 | public function map(\Closure $callback) |
||
147 | |||
148 | /** |
||
149 | * Get the collection of items as JSON. |
||
150 | * |
||
151 | * @param int $options |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function asJson($options = 0) |
||
159 | |||
160 | /** |
||
161 | * Count the number of items in the collection. |
||
162 | * |
||
163 | * @return int |
||
164 | */ |
||
165 | public function count() |
||
169 | |||
170 | /** |
||
171 | * Get an iterator for the items. |
||
172 | * |
||
173 | * @return ArrayIterator |
||
174 | */ |
||
175 | public function getIterator() |
||
179 | |||
180 | /** |
||
181 | * Determine if an item exists at an offset. |
||
182 | * |
||
183 | * @param mixed $key |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function offsetExists($key) |
||
191 | |||
192 | /** |
||
193 | * Get an item at a given offset. |
||
194 | * |
||
195 | * @param mixed $key |
||
196 | * |
||
197 | * @return mixed |
||
198 | */ |
||
199 | public function offsetGet($key) |
||
203 | |||
204 | /** |
||
205 | * Set the item at a given offset. |
||
206 | * |
||
207 | * @param mixed $key |
||
208 | * @param mixed $value |
||
209 | * |
||
210 | * @return void |
||
211 | */ |
||
212 | public function offsetSet($key, $value) |
||
220 | |||
221 | /** |
||
222 | * Unset the item at a given offset. |
||
223 | * |
||
224 | * @param string $key |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | public function offsetUnset($key) |
||
232 | |||
233 | /** |
||
234 | * Convert the collection to its string representation. |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | public function __toString() |
||
242 | } |
||
243 |