1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Spl\DataStructures;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* O2System Standard PHP Libraries ArrayObject
|
20
|
|
|
*
|
21
|
|
|
* @package O2System\Core\SPL
|
22
|
|
|
*/
|
23
|
|
|
class SplArrayObject extends \ArrayObject
|
24
|
|
|
{
|
25
|
|
|
use Traits\ArrayConversionTrait;
|
26
|
|
|
use Traits\ArrayFunctionsTrait;
|
27
|
|
|
|
28
|
|
|
// ------------------------------------------------------------------------
|
29
|
|
|
|
30
|
|
|
/**
|
31
|
|
|
* SplArrayObject::__construct
|
32
|
|
|
*
|
33
|
|
|
* @see http://php.net/manual/en/class.arrayobject.php
|
34
|
|
|
*
|
35
|
|
|
* @param array $array Initial Array
|
36
|
|
|
* @param int $flag ArrayObject Flags
|
37
|
|
|
*
|
38
|
|
|
* @return SplArrayObject Returns an SplArrayObject object on success.
|
39
|
|
|
*/
|
40
|
|
|
public function __construct(array $array = [], $flag = \ArrayObject::ARRAY_AS_PROPS)
|
41
|
|
|
{
|
42
|
|
|
parent::__construct($array, $flag);
|
43
|
|
|
}
|
44
|
|
|
|
45
|
|
|
// ------------------------------------------------------------------------
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* SplArrayObject::isEmpty
|
49
|
|
|
*
|
50
|
|
|
* Checks if the array storage is empty.
|
51
|
|
|
*
|
52
|
|
|
* @return bool
|
53
|
|
|
*/
|
54
|
|
|
public function isEmpty()
|
55
|
|
|
{
|
56
|
|
|
return ($this->count() == 0 ? true : false);
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
// -----------------------------------------------------------------------
|
60
|
|
|
|
61
|
|
|
/**
|
62
|
|
|
* SplArrayObject::__get
|
63
|
|
|
*
|
64
|
|
|
* @see http://php.net/manual/en/arrayobject.offsetget.php
|
65
|
|
|
*
|
66
|
|
|
* @param string $offset The offset with the value.
|
67
|
|
|
*
|
68
|
|
|
* @return mixed The value at the specified index or false.
|
69
|
|
|
*/
|
70
|
|
|
public function __get($offset)
|
71
|
|
|
{
|
72
|
|
|
return $this->offsetGet($offset);
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
// ------------------------------------------------------------------------
|
76
|
|
|
|
77
|
|
|
public function offsetGet($offset)
|
78
|
|
|
{
|
79
|
|
|
if ($this->offsetExists($offset) === false) {
|
80
|
|
|
return false;
|
81
|
|
|
}
|
82
|
|
|
|
83
|
|
|
return parent::offsetGet($offset);
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
// ------------------------------------------------------------------------
|
87
|
|
|
|
88
|
|
|
/**
|
89
|
|
|
* SplArrayObject::exchangeOffset
|
90
|
|
|
*
|
91
|
|
|
* Exchange the storage offset into camelcase
|
92
|
|
|
*
|
93
|
|
|
* @return array Returns the new array storage
|
94
|
|
|
*/
|
95
|
|
|
public function exchangeOffset()
|
96
|
|
|
{
|
97
|
|
|
if ($this->count() > 0) {
|
98
|
|
|
$camelcaseStorage = [];
|
99
|
|
|
|
100
|
|
|
foreach ($this->getArrayCopy() as $offset => $value) {
|
101
|
|
|
$camelcaseStorage[ camelcase($offset) ] = $value;
|
|
|
|
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
$this->exchangeArray($camelcaseStorage);
|
105
|
|
|
}
|
106
|
|
|
|
107
|
|
|
return $this->getArrayCopy();
|
108
|
|
|
}
|
109
|
|
|
|
110
|
|
|
// ------------------------------------------------------------------------
|
111
|
|
|
|
112
|
|
|
/**
|
113
|
|
|
* SplArrayObject::merge
|
114
|
|
|
*
|
115
|
|
|
* Merge array of values into the storage
|
116
|
|
|
*
|
117
|
|
|
* @param array $values Variable list of arrays to merge.
|
118
|
|
|
*
|
119
|
|
|
* @return array The array merged copy of the resulting array
|
120
|
|
|
*/
|
121
|
|
|
public function merge(array $values)
|
122
|
|
|
{
|
123
|
|
|
$storage = $this->getArrayCopy();
|
124
|
|
|
$storage = array_merge($storage, $values);
|
125
|
|
|
|
126
|
|
|
$this->exchangeArray($storage);
|
127
|
|
|
|
128
|
|
|
return $storage;
|
129
|
|
|
}
|
130
|
|
|
} |