1 | <?php |
||
9 | class DTOBase implements ArrayAccess, IteratorAggregate, Countable |
||
10 | { |
||
11 | protected $data; |
||
12 | protected $default = []; |
||
13 | private $serializer = null; |
||
14 | |||
15 | use DTOAccessorTrait; |
||
16 | use DTOIteratorTrait; |
||
17 | |||
18 | /** |
||
19 | * DTO constructor. |
||
20 | * @param array $default |
||
21 | * @param array|object|string $data |
||
22 | * @param DTOSerializerInterface $serializer |
||
23 | * @throws \InvalidArgumentException |
||
24 | */ |
||
25 | 40 | public function __construct($default = [], $data = [], DTOSerializerInterface $serializer = null) |
|
35 | |||
36 | /** |
||
37 | * Get value by key or nested structure |
||
38 | * @param string $offset |
||
39 | * @return mixed |
||
40 | * @throws \InvalidArgumentException |
||
41 | */ |
||
42 | 23 | public function get($offset) |
|
50 | |||
51 | /** |
||
52 | * Converts data to string |
||
53 | * @return string |
||
54 | */ |
||
55 | 3 | public function __toString() |
|
59 | |||
60 | /** |
||
61 | * Converts data to string |
||
62 | * @return string |
||
63 | */ |
||
64 | 2 | public function toArray() |
|
72 | |||
73 | /** |
||
74 | * Serializes the data using serializer |
||
75 | * @return string |
||
76 | */ |
||
77 | 4 | private function serialize() |
|
81 | |||
82 | /** |
||
83 | * @return DTOSerializerInterface |
||
84 | */ |
||
85 | 4 | public function getSerializer() |
|
89 | |||
90 | /** |
||
91 | * @param DTOSerializerInterface $serializer |
||
92 | * @return DTOBase |
||
93 | */ |
||
94 | 1 | public function setSerializer(DTOSerializerInterface $serializer) |
|
100 | |||
101 | /** |
||
102 | * @return array |
||
103 | */ |
||
104 | 36 | public function getDefault() |
|
108 | |||
109 | /** |
||
110 | * Get nested values using "dot" notation |
||
111 | * @param $offset |
||
112 | * @return mixed |
||
113 | * @throws \InvalidArgumentException |
||
114 | */ |
||
115 | 5 | private function processChain($offset) |
|
131 | } |