@@ -47,34 +47,6 @@ public function get(?string $fallback = null): mixed
4747 return (!is_null ($ this ->row ) ? $ this ->row : $ fallback );
4848 }
4949
50- /**
51- * Traverse factory
52- * If you want
53- * @return self
54- */
55- public function __call ($ method , $ args )
56- {
57- $ this ->row = ($ this ->{$ method } ?? null );
58- $ this ->raw = $ this ->row ;
59-
60- if (count ($ args ) > 0 ) {
61- $ name = ucfirst ($ args [0 ]);
62- $ className = "MaplePHP \\DTO \\Format \\{$ name }" ;
63- if (!class_exists ($ className )) {
64- throw new \Exception ("The DTO Format class do not exist! " , 1 );
65- }
66- $ reflect = new \ReflectionClass ($ className );
67- $ instance = $ reflect ->newInstanceWithoutConstructor ();
68- return $ instance ->value ($ this ->row );
69- }
70-
71- if (is_array ($ this ->row ) || is_object ($ this ->row )) {
72- return $ this ::value ($ this ->row , $ this ->raw );
73- }
74-
75- return self ::value ($ this ->row );
76- }
77-
7850 /**
7951 * Get raw
8052 * @return mixed
@@ -84,24 +56,16 @@ public function getRaw()
8456 return $ this ->raw ;
8557 }
8658
59+
8760 /**
88- * Callable factory
89- * @psalm-suppress InvalidFunctionCall Psalm do not understand that $call is callable
90- * @return mixed
61+ * Json decode value
62+ * @return self
9163 */
92- /*
93- public function fetchFactory(): mixed
64+ public function jsonDecode (): self
9465 {
95- return function ($arr, $row, $_unusedKey, $index) {
96- $data = array_values($this->raw);
97- $call = (isset($data[$index])) ? $data[$index] : null;
98- if (is_callable($call)) {
99- return $call($arr, $row);
100- }
101- return false;
102- };
66+ $ this ->row = json_decode ($ this ->row );
67+ return $ this ::value ($ this ->row );
10368 }
104- */
10569
10670 /**
10771 * Access incremental array
@@ -113,13 +77,13 @@ public function fetch(?callable $callback = null)
11377 $ index = 0 ;
11478 $ new = array ();
11579
116- if (is_null ($ this ->raw )) {
117- $ this ->raw = $ this ->data ;
80+ if (is_null ($ this ->row )) {
81+ $ this ->row = $ this ->data ;
11882 }
11983
120- foreach ($ this ->raw as $ key => $ row ) {
84+ foreach ($ this ->row as $ key => $ row ) {
12185 if (!is_null ($ callback )) {
122- if (($ get = $ callback ($ this ::value ($ this ->raw ), $ row , $ key , $ index )) !== false ) {
86+ if (($ get = $ callback ($ this ::value ($ this ->row ), $ row , $ key , $ index )) !== false ) {
12387 $ new [$ key ] = $ get ;
12488 }
12589 } else {
@@ -142,7 +106,6 @@ public function fetch(?callable $callback = null)
142106 return $ this ;
143107 }
144108
145-
146109 /**
147110 * Chech if current traverse data is equal to val
148111 * @param string $isVal
@@ -196,4 +159,32 @@ public function sprint(string $add)
196159 }
197160 return $ this ;
198161 }
162+
163+ /**
164+ * Traverse factory
165+ * If you want
166+ * @return self
167+ */
168+ public function __call ($ method , $ args )
169+ {
170+ $ this ->row = ($ this ->{$ method } ?? null );
171+ $ this ->raw = $ this ->row ;
172+
173+ if (count ($ args ) > 0 ) {
174+ $ name = ucfirst ($ args [0 ]);
175+ $ className = "MaplePHP \\DTO \\Format \\{$ name }" ;
176+ if (!class_exists ($ className )) {
177+ throw new \Exception ("The DTO Format class do not exist! " , 1 );
178+ }
179+ $ reflect = new \ReflectionClass ($ className );
180+ $ instance = $ reflect ->newInstanceWithoutConstructor ();
181+ return $ instance ->value ($ this ->row );
182+ }
183+
184+ if (is_array ($ this ->row ) || is_object ($ this ->row )) {
185+ return $ this ::value ($ this ->row , $ this ->raw );
186+ }
187+
188+ return self ::value ($ this ->row );
189+ }
199190}
0 commit comments