1 | <?php |
||
9 | class Converter |
||
10 | { |
||
11 | 23 | protected function isTuple($array) |
|
21 | |||
22 | 23 | public function toObject($data) |
|
23 | { |
||
24 | 23 | if (is_array($data)) { |
|
25 | 23 | if ($this->isTuple($data)) { |
|
26 | 1 | return $this->convertArrayToObject($data); |
|
27 | } |
||
28 | } |
||
29 | |||
30 | 23 | $data = (object) $data; |
|
31 | |||
32 | 23 | foreach ($data as $k => $v) { |
|
33 | 23 | if (is_array($v) && $this->isTuple($v)) { |
|
34 | 23 | $data->$k = $this->convertArrayToObject($v); |
|
35 | 23 | } elseif(is_array($v) || is_object($v)) { |
|
36 | 23 | $data->$k = $this->toObject($v); |
|
37 | } |
||
38 | } |
||
39 | |||
40 | 23 | return $data; |
|
41 | } |
||
42 | |||
43 | 23 | public function convertArrayToObject($data) |
|
57 | |||
58 | 1 | public function toArray($data) : array |
|
59 | { |
||
60 | 1 | if (!$data) { |
|
61 | 1 | return []; |
|
62 | } |
||
63 | |||
64 | 1 | if (is_object($data)) { |
|
65 | 1 | $data = get_object_vars($data); |
|
66 | } |
||
67 | |||
68 | 1 | foreach ($data as $k => $v) { |
|
69 | 1 | if (is_array($v) || is_object($v)) { |
|
70 | 1 | $data[$k] = $this->toArray($v); |
|
71 | } |
||
72 | } |
||
73 | |||
74 | 1 | return $data; |
|
75 | } |
||
76 | |||
77 | private $underscores = []; |
||
78 | |||
79 | 1 | public function toUnderscore(string $input) : string |
|
91 | |||
92 | private $camelcased = []; |
||
93 | |||
94 | 1 | public function toCamelCase(string $string, bool $capitalize = false) : string |
|
113 | } |
||
114 |