@@ -27,10 +27,8 @@ final class Api extends Controller
27
27
*
28
28
* | ANY REQUEST FROM API ENDPOINT
29
29
*
30
- *
31
30
* | Accept all type of request or any other method
32
31
*
33
- *
34
32
* | Cannot evaluate `{?} URL parameters` in api route if it's an array
35
33
* |
36
34
*
@@ -39,14 +37,10 @@ final class Api extends Controller
39
37
*
40
38
* ------------------------------------------------------------------------
41
39
*/
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
+ {
47
42
try
48
43
{
49
- $ real_route = $ route ;
50
44
$ dir = Route::$ root_dir ;
51
45
52
46
// will store all the parameters value in this array
@@ -56,6 +50,16 @@ final public static function any(
56
50
// will store all the parameters names in this array
57
51
$ paramKey = [];
58
52
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
+
59
63
// finding if there is any {?} parameter in $route
60
64
if (is_string ($ route ))
61
65
{
@@ -78,24 +82,19 @@ final public static function any(
78
82
79
83
if ($ class_method )
80
84
{
81
- ob_start ();
82
- $ web_file = include $ dir . "/src/web.php " ;
83
- ob_end_clean ();
84
-
85
85
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 )
89
88
)
90
89
{
91
90
http_response_code (200 );
92
91
header ("Content-Type: application/json " );
93
92
94
- print_r (self ::controller ($ web_file [ $ real_route ] , $ class_method ));
93
+ print_r (self ::controller ($ const_types_class , $ const_types_method ));
95
94
}
96
95
else
97
96
{
98
- throw new Exception ("API route class is not registered! " );
97
+ throw new Exception ("Invalid api controller class or not existing: " . $ const_types_class );
99
98
}
100
99
101
100
self ::log ();
@@ -204,28 +203,23 @@ final public static function any(
204
203
exit ("Method Not Allowed " );
205
204
}
206
205
207
- ob_start ();
208
- $ web_file = include $ dir . "/src/web.php " ;
209
- ob_end_clean ();
210
-
211
206
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 )
215
209
)
216
210
{
217
211
http_response_code (200 );
218
212
header ("Content-Type: application/json " );
219
213
220
214
print_r (
221
- self ::controller ($ web_file [ $ real_route ] , $ class_method , [
215
+ self ::controller ($ const_types_class , $ const_types_method , [
222
216
...$ req_value ,
223
217
]),
224
218
);
225
219
}
226
220
else
227
221
{
228
- throw new Exception ("API route class is not registered! " );
222
+ throw new Exception ("Invalid api controller class or not existing: " . $ const_types_class );
229
223
}
230
224
231
225
self ::log ();
@@ -252,7 +246,7 @@ final public static function any(
252
246
*/
253
247
public static function get (
254
248
array |string $ route ,
255
- string $ class_method = " __invoke " ,
249
+ int $ class_method ,
256
250
) {
257
251
self ::any ($ route , $ class_method , "GET " );
258
252
}
@@ -270,7 +264,7 @@ public static function get(
270
264
*/
271
265
public static function post (
272
266
array |string $ route ,
273
- string $ class_method = " __invoke " ,
267
+ int $ class_method ,
274
268
) {
275
269
self ::any ($ route , $ class_method , "POST " );
276
270
}
@@ -288,7 +282,7 @@ public static function post(
288
282
*/
289
283
public static function put (
290
284
array |string $ route ,
291
- string $ class_method = " __invoke " ,
285
+ int $ class_method ,
292
286
) {
293
287
self ::any ($ route , $ class_method , "PUT " );
294
288
}
@@ -306,7 +300,7 @@ public static function put(
306
300
*/
307
301
public static function update (
308
302
array |string $ route ,
309
- string $ class_method = " __invoke " ,
303
+ int $ class_method ,
310
304
) {
311
305
self ::any ($ route , $ class_method , "UPDATE " );
312
306
}
@@ -324,7 +318,7 @@ public static function update(
324
318
*/
325
319
public static function patch (
326
320
array |string $ route ,
327
- string $ class_method = " __invoke " ,
321
+ int $ class_method ,
328
322
) {
329
323
self ::any ($ route , $ class_method , "PATCH " );
330
324
}
@@ -342,7 +336,7 @@ public static function patch(
342
336
*/
343
337
public static function delete (
344
338
array |string $ route ,
345
- string $ class_method = " __invoke " ,
339
+ int $ class_method ,
346
340
) {
347
341
self ::any ($ route , $ class_method , "DELETE " );
348
342
}
0 commit comments