Skip to content

Commit d806625

Browse files
authored
Merge pull request #22 from dconco/dev-1
Updated to version v1.2.1-alpha pre-release
2 parents a55be86 + 52a6610 commit d806625

File tree

18 files changed

+458
-407
lines changed

18 files changed

+458
-407
lines changed

.env

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
APP_NAME = 'PhpSlides'
2-
APP_VERSION = '1.0.0'
2+
APP_VERSION = '1.2.1'
33
APP_SERVER = 'localhost'
44

55
## DATABASE INFO
66
DB_USER = 'root'
77
DB_PASS = 'root'
88
DB_HOST = 'localhost'
9-
DB_BASE = 'php_slides'
10-
11-
## MAILER INFO
9+
DB_BASE = 'php_slides'

App/Controller/ApiController.php

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

App/Controller/ClassController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected static function __class(object|string $class, string $method, array|nu
4040
}
4141
else
4242
{
43-
throw new Exception("No Controller class found in - $class", 1);
43+
throw new Exception("No Controller class found as - $class", 1);
4444
}
4545
}
4646
catch ( Exception $e )

App/Controller/RouteController.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function slides_include($filename)
7575
$file_contents = preg_replace_callback('/<\? ([^?]*)\?>/s', function ($matches)
7676
{
7777
$val = trim($matches[1]);
78-
return "<?php echo($val) ?>";
78+
return "<?php print_r($val) ?>";
7979
}, $file_contents);
8080

8181
$file_contents = str_replace('::view/', $view, $file_contents);
@@ -122,10 +122,7 @@ public static function slides_include($filename)
122122
* | --------------------
123123
* ==============================
124124
*/
125-
protected static function routing(
126-
array|string $route,
127-
$callback,
128-
string $method = "*",
125+
protected static function routing(array|string $route, mixed $callback, string $method = "*",
129126
) {
130127
$uri = [];
131128
$str_route = "";
@@ -256,7 +253,7 @@ protected static function class_info(array $class_info, array|null $param)
256253
)
257254
{
258255
throw new Exception(
259-
"No Controller method found as $method. Try using __invoke method.",
256+
"No Controller method found as '$method'. Try using __invoke method.",
260257
1
261258
);
262259
}

0 commit comments

Comments
 (0)