1 | <?php |
||
5 | abstract class Base implements \ArrayAccess |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * Base constructor - you may use an array to initialize the Transfer |
||
10 | */ |
||
11 | 62 | public function __construct(array $data = array()) |
|
26 | |||
27 | /** |
||
28 | * Getter and Setters |
||
29 | */ |
||
30 | 39 | public function __call($name, array $args) |
|
51 | |||
52 | /** |
||
53 | * Export transfer values as an array |
||
54 | * @return array |
||
55 | */ |
||
56 | 9 | public function toArray() |
|
57 | { |
||
58 | 9 | $ref = new \ReflectionObject($this); |
|
59 | 9 | $export = array(); |
|
60 | |||
61 | 9 | foreach ($ref->getProperties() as $property) { |
|
62 | 9 | $property->setAccessible(true); |
|
63 | 9 | $name = strtolower(preg_replace('@([A-Z])@', '_\1', $property->getName())); |
|
64 | 9 | $export[$name] = $property->getValue($this); |
|
65 | |||
66 | 9 | if ($export[$name] instanceof self) { |
|
67 | 1 | $export[$name] = $export[$name]->toArray(); |
|
68 | 1 | } |
|
69 | |||
70 | 9 | if ($export[$name] instanceof \DateTime) { |
|
71 | 1 | $export[$name] = $export[$name]->format('Y-m-d'); |
|
72 | 1 | } |
|
73 | 9 | } |
|
74 | |||
75 | 9 | return $export; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Export transfer values as an array in studly caps format. |
||
80 | * @return array |
||
81 | */ |
||
82 | 1 | public function toStudlyCapsArray() |
|
93 | |||
94 | /** |
||
95 | * toArray with unset null fields |
||
96 | * @return array |
||
97 | */ |
||
98 | 6 | public function toCleanArray() |
|
111 | |||
112 | /** |
||
113 | * Extract transfer $property value from $data |
||
114 | */ |
||
115 | 38 | private function getValue(array $data, $property) |
|
128 | |||
129 | 2 | private function toCamelCase($name) |
|
133 | |||
134 | 1 | public function offsetGet($offset) |
|
139 | |||
140 | 1 | public function offsetSet($offset, $value) |
|
145 | |||
146 | 1 | public function offsetExists($offset) |
|
151 | |||
152 | 1 | public function offsetUnset($offset) |
|
156 | } |
||
157 |