@@ -27,10 +27,8 @@ final class Api extends Controller
2727 *
2828 * | ANY REQUEST FROM API ENDPOINT
2929 *
30- *
3130 * | Accept all type of request or any other method
3231 *
33- *
3432 * | Cannot evaluate `{?} URL parameters` in api route if it's an array
3533 * |
3634 *
@@ -39,14 +37,10 @@ final class Api extends Controller
3937 *
4038 * ------------------------------------------------------------------------
4139 */
42- final public static function any (
43- array |string $ route ,
44- int $ class_method ,
45- string $ method = "* " ,
46- ) {
40+ final public static function any (array |string $ route , int $ class_method , string $ method = "* " )
41+ {
4742 try
4843 {
49- $ real_route = $ route ;
5044 $ dir = Route::$ root_dir ;
5145
5246 // will store all the parameters value in this array
@@ -56,6 +50,16 @@ final public static function any(
5650 // will store all the parameters names in this array
5751 $ paramKey = [];
5852
53+
54+ // Gets all constant int values wrapped in an array
55+ ob_start ();
56+ $ bin_const_types = include $ dir . "/App/bin/const_types.php " ;
57+ ob_end_clean ();
58+
59+ $ bin_const_types = unserialize (hex2bin (($ bin_const_types )));
60+ $ const_types_method = $ bin_const_types [$ class_method ][1 ];
61+ $ const_types_class = $ bin_const_types [$ class_method ][0 ];
62+
5963 // finding if there is any {?} parameter in $route
6064 if (is_string ($ route ))
6165 {
@@ -78,24 +82,19 @@ final public static function any(
7882
7983 if ($ class_method )
8084 {
81- ob_start ();
82- $ web_file = include $ dir . "/src/web.php " ;
83- ob_end_clean ();
84-
8585 if (
86- array_key_exists ($ real_route , $ web_file ) &&
87- (preg_match ("/(Controller)/ " , $ web_file [$ real_route ], $ matches ) &&
88- count ($ matches ) > 1 )
86+ (preg_match ("/(Controller)/ " , $ const_types_class , $ matches ) && count ($ matches ) > 1 ) &&
87+ (preg_match ("/(Api)/ " , $ const_types_class , $ matches ) && count ($ matches ) > 0 )
8988 )
9089 {
9190 http_response_code (200 );
9291 header ("Content-Type: application/json " );
9392
94- print_r (self ::controller ($ web_file [ $ real_route ] , $ class_method ));
93+ print_r (self ::controller ($ const_types_class , $ const_types_method ));
9594 }
9695 else
9796 {
98- throw new Exception ("API route class is not registered! " );
97+ throw new Exception ("Invalid api controller class or not existing: " . $ const_types_class );
9998 }
10099
101100 self ::log ();
@@ -204,28 +203,23 @@ final public static function any(
204203 exit ("Method Not Allowed " );
205204 }
206205
207- ob_start ();
208- $ web_file = include $ dir . "/src/web.php " ;
209- ob_end_clean ();
210-
211206 if (
212- array_key_exists ($ real_route , $ web_file ) &&
213- (preg_match ("/(Controller)/ " , $ web_file [$ real_route ], $ matches ) &&
214- count ($ matches ) > 1 )
207+ (preg_match ("/(Controller)/ " , $ const_types_class , $ matches ) && count ($ matches ) > 1 ) &&
208+ (preg_match ("/(Api)/ " , $ const_types_class , $ matches ) && count ($ matches ) > 0 )
215209 )
216210 {
217211 http_response_code (200 );
218212 header ("Content-Type: application/json " );
219213
220214 print_r (
221- self ::controller ($ web_file [ $ real_route ] , $ class_method , [
215+ self ::controller ($ const_types_class , $ const_types_method , [
222216 ...$ req_value ,
223217 ]),
224218 );
225219 }
226220 else
227221 {
228- throw new Exception ("API route class is not registered! " );
222+ throw new Exception ("Invalid api controller class or not existing: " . $ const_types_class );
229223 }
230224
231225 self ::log ();
@@ -252,7 +246,7 @@ final public static function any(
252246 */
253247 public static function get (
254248 array |string $ route ,
255- string $ class_method = " __invoke " ,
249+ int $ class_method ,
256250 ) {
257251 self ::any ($ route , $ class_method , "GET " );
258252 }
@@ -270,7 +264,7 @@ public static function get(
270264 */
271265 public static function post (
272266 array |string $ route ,
273- string $ class_method = " __invoke " ,
267+ int $ class_method ,
274268 ) {
275269 self ::any ($ route , $ class_method , "POST " );
276270 }
@@ -288,7 +282,7 @@ public static function post(
288282 */
289283 public static function put (
290284 array |string $ route ,
291- string $ class_method = " __invoke " ,
285+ int $ class_method ,
292286 ) {
293287 self ::any ($ route , $ class_method , "PUT " );
294288 }
@@ -306,7 +300,7 @@ public static function put(
306300 */
307301 public static function update (
308302 array |string $ route ,
309- string $ class_method = " __invoke " ,
303+ int $ class_method ,
310304 ) {
311305 self ::any ($ route , $ class_method , "UPDATE " );
312306 }
@@ -324,7 +318,7 @@ public static function update(
324318 */
325319 public static function patch (
326320 array |string $ route ,
327- string $ class_method = " __invoke " ,
321+ int $ class_method ,
328322 ) {
329323 self ::any ($ route , $ class_method , "PATCH " );
330324 }
@@ -342,7 +336,7 @@ public static function patch(
342336 */
343337 public static function delete (
344338 array |string $ route ,
345- string $ class_method = " __invoke " ,
339+ int $ class_method ,
346340 ) {
347341 self ::any ($ route , $ class_method , "DELETE " );
348342 }
0 commit comments