-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayObject.php
67 lines (56 loc) · 1.35 KB
/
ArrayObject.php
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
<?php
/**
* --------------------------------
* PEL - Phalcon Extensions Library
* --------------------------------
*
* This code is distributed under New BSD license.
* License is bundled with this package in file LICENSE.txt.
*
* @author Jiri Pazdernik <[email protected]>
*/
namespace Pel;
/**
* Class extending default PHP ArrayObject class
*
* @author Jiri Pazdernik <[email protected]>
*/
class ArrayObject extends \ArrayObject
{
/**
* Constructor
*
* @see \ArrayObject class
* @param array $input
* @param integer $flags
* @param string $iteratorClass
*/
public function __construct($input = array(), $flags = \ArrayObject::ARRAY_AS_PROPS, $iteratorClass = "ArrayIterator")
{
$items = array();
foreach ($input as $key => $item) {
if (is_array($item)) {
$item = new ArrayObject($item, $flags, $iteratorClass);
}
$items[$key] = $item;
}
parent::__construct($items, $flags, $iteratorClass);
}
/**
* Return data as an array
*
* @param boolean $recursive TRUE for convert children to array
* @return array
*/
public function toArray($recursive = false)
{
$result = array();
foreach ($this as $key => $val) {
if ((true === $recursive) && is_object($val) && method_exists($val, "toArray")) {
$val = $val->toArray();
}
$result[$key] = $val;
}
return $result;
}
}