forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistry.zep
267 lines (242 loc) · 6.35 KB
/
Registry.zep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon;
use Traversable;
/**
* Phalcon\Registry
*
* A registry is a container for storing objects and values in the application
* space. By storing the value in a registry, the same object is always
* available throughout your application.
*
*```php
* $registry = new \Phalcon\Registry();
*
* // Set value
* $registry->something = "something";
* // or
* $registry["something"] = "something";
*
* // Get value
* $value = $registry->something;
* // or
* $value = $registry["something"];
*
* // Check if the key exists
* $exists = isset($registry->something);
* // or
* $exists = isset($registry["something"]);
*
* // Unset
* unset($registry->something);
* // or
* unset($registry["something"]);
*```
*
* In addition to ArrayAccess, Phalcon\Registry also implements Countable
* (count($registry) will return the number of elements in the registry),
* Serializable and Iterator (you can iterate over the registry using a foreach
* loop) interfaces. For PHP 5.4 and higher, JsonSerializable interface is
* implemented.
*
* Phalcon\Registry is very fast (it is typically faster than any userspace
* implementation of the registry); however, this comes at a price:
* Phalcon\Registry is a final class and cannot be inherited from.
*
* Though Phalcon\Registry exposes methods like __get(), offsetGet(), count() etc,
* it is not recommended to invoke them manually (these methods exist mainly to
* match the interfaces the registry implements): $registry->__get("property")
* is several times slower than $registry->property.
*
* Internally all the magic methods (and interfaces except JsonSerializable)
* are implemented using object handlers or similar techniques: this allows to
* bypass relatively slow method calls.
*/
final class Registry extends Collection
{
/**
* Constructor
*/
final public function __construct(array! data = null)
{
parent::__construct(data);
}
/**
* Magic getter to get an element from the collection
*/
final public function __get(string! element) -> var
{
return parent::get(element);
}
/**
* Magic isset to check whether an element exists or not
*/
final public function __isset(string! element) -> bool
{
return parent::has(element);
}
/**
* Magic setter to assign values to an element
*/
final public function __set(string! element, var value) -> void
{
parent::set(element, value);
}
/**
* Magic unset to remove an element from the collection
*/
final public function __unset(string! element) -> void
{
parent::remove(element);
}
/**
* Clears the internal collection
*/
final public function clear() -> void
{
parent::clear();
}
/**
* Count elements of an object
*
* @link https://php.net/manual/en/countable.count.php
*/
final public function count() -> int
{
return parent::count();
}
/**
* Get the element from the collection
*/
final public function get(
string! element,
var defaultValue = null,
string! cast = null
) -> var {
return parent::get(element, defaultValue, cast);
}
/**
* Returns the iterator of the class
*/
final public function getIterator() -> <Traversable>
{
return parent::getIterator();
}
/**
* Get the element from the collection
*/
final public function has(string! element) -> bool
{
return parent::has(element);
}
/**
* Initialize internal array
*/
final public function init(array! data = []) -> void
{
parent::init(data);
}
/**
* Specify data which should be serialized to JSON
*
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
*/
final public function jsonSerialize () -> array
{
return parent::jsonSerialize();
}
/**
* Whether a offset exists
*
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
*/
final public function offsetExists(var element) -> bool
{
return parent::has(element);
}
/**
* Offset to retrieve
*
* @link https://php.net/manual/en/arrayaccess.offsetget.php
*/
final public function offsetGet(var element) -> var
{
return parent::get(element);
}
/**
* Offset to set
*
* @link https://php.net/manual/en/arrayaccess.offsetset.php
*/
final public function offsetSet(var element, var value) -> void
{
parent::set(element, value);
}
/**
* Offset to unset
*
* @link https://php.net/manual/en/arrayaccess.offsetunset.php
*/
final public function offsetUnset(var element) -> void
{
parent::remove(element);
}
/**
* Delete the element from the collection
*/
final public function remove(string! element) -> void
{
parent::remove(element);
}
/**
* String representation of object
*
* @link https://php.net/manual/en/serializable.serialize.php
*/
final public function serialize() -> string
{
return parent::serialize();
}
/**
* Set an element in the collection
*/
final public function set(string! element, var value) -> void
{
parent::set(element, value);
}
/**
* Returns the object in an array format
*/
final public function toArray() -> array
{
return parent::toArray();
}
/**
* Returns the object in a JSON format
*
* The default string uses the following options for json_encode
*
* JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES
*
* @see https://www.ietf.org/rfc/rfc4627.txt
*/
final public function toJson(int options = 79) -> string
{
return parent::toJson(options);
}
/**
* Constructs the object
*
* @link https://php.net/manual/en/serializable.unserialize.php
*/
final public function unserialize(var serialized) -> void
{
parent::unserialize(serialized);
}
}