1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by Gorlum 21.08.2016 3:00 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Common; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ObjectCollection |
12
|
|
|
* |
13
|
|
|
* Remaps ArrayAccess interface to work with indexed objects only |
14
|
|
|
* Counts only indexed elements |
15
|
|
|
* |
16
|
|
|
* @package Common |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class ObjectCollection extends IndexedObjectStorage { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Whether a offset exists |
23
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetexists.php |
24
|
|
|
* |
25
|
|
|
* @param mixed $offset <p> |
26
|
|
|
* An offset to check for. |
27
|
|
|
* </p> |
28
|
|
|
* |
29
|
|
|
* @return boolean true on success or false on failure. |
30
|
|
|
* </p> |
31
|
|
|
* <p> |
32
|
|
|
* The return value will be casted to boolean if non-boolean was returned. |
33
|
|
|
* @since 5.0.0 |
34
|
|
|
*/ |
35
|
1 |
|
public function offsetExists($offset) { |
36
|
1 |
|
return $this->indexIsSet($offset); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Offset to retrieve |
41
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetget.php |
42
|
|
|
* |
43
|
|
|
* @param mixed $offset <p> |
44
|
|
|
* The offset to retrieve. |
45
|
|
|
* </p> |
46
|
|
|
* |
47
|
|
|
* @return mixed Can return all value types. |
48
|
|
|
* @since 5.0.0 |
49
|
|
|
*/ |
50
|
1 |
|
public function offsetGet($offset) { |
51
|
1 |
|
return $this->indexGetObject($offset); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Offset to set |
56
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetset.php |
57
|
|
|
* |
58
|
|
|
* @param mixed $offset <p> |
59
|
|
|
* The offset to assign the value to. |
60
|
|
|
* </p> |
61
|
|
|
* @param mixed $value <p> |
62
|
|
|
* The value to set. |
63
|
|
|
* </p> |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
* @since 5.0.0 |
67
|
|
|
*/ |
68
|
1 |
|
public function offsetSet($offset, $value) { |
69
|
1 |
|
$this->attach($value, $offset); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Offset to unset |
74
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetunset.php |
75
|
|
|
* |
76
|
|
|
* @param mixed $offset <p> |
77
|
|
|
* The offset to unset. |
78
|
|
|
* </p> |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
* @since 5.0.0 |
82
|
|
|
*/ |
83
|
1 |
|
public function offsetUnset($offset) { |
84
|
1 |
|
if($this->offsetExists($offset)) { |
85
|
1 |
|
parent::offsetUnset($this->offsetGet($offset)); |
86
|
1 |
|
} |
87
|
1 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Counts ONLY indexed elements |
91
|
|
|
* |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
1 |
|
public function count() { |
95
|
1 |
|
return count($this->index); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|