22
33use PhpSlides \Route ;
44use PhpSlides \Exception ;
5+ use PhpSlides \Http \Request ;
56use PhpSlides \Loader \ViewLoader ;
67use PhpSlides \Loader \FileLoader ;
78use PhpSlides \Foundation \Application ;
1314const POST = 'POST ' ;
1415const PATCH = 'PATCH ' ;
1516const DELETE = 'DELETE ' ;
16- const RELATIVE_PATH = 'path ' ;
17- const ABSOLUTE_PATH = 'root_path ' ;
17+ const REMOTE_PATH = 2 ;
18+ const RELATIVE_PATH = 0 ;
19+ const ABSOLUTE_PATH = 1 ;
1820
1921/**
2022 * -----------------------------------------------------------
2729 * |
2830 * -----------------------------------------------------------
2931 */
30- function psl (string $ filename , mixed ...$ props ): mixed
32+ function component (string $ filename , mixed ...$ props ): mixed
3133{
3234 $ loaded = (new ViewLoader ())->load ($ filename , ...$ props );
3335 return $ loaded ->getLoad ();
@@ -61,7 +63,7 @@ function add_route_name(string $name, string|array $value): void
6163 */
6264function route (
6365 string |null $ name = null ,
64- array |null $ param = null
66+ array |null $ param = null ,
6567): array |object |string {
6668 $ routes = $ GLOBALS ['__routes ' ] ?? [];
6769
@@ -73,7 +75,7 @@ function route(
7375 $ route_class ->$ key = function (string ...$ args ) use (
7476 $ routes ,
7577 $ value ,
76- $ key
78+ $ key,
7779 ) {
7880 $ route = '' ;
7981
@@ -86,14 +88,14 @@ function route(
8688 '/\{[^}]+\}/ ' ,
8789 $ args [$ i ],
8890 $ value ,
89- 1
91+ 1 ,
9092 );
9193 } else {
9294 $ route = preg_replace (
9395 '/\{[^}]+\}/ ' ,
9496 $ args [$ i ],
9597 $ route ,
96- 1
98+ 1 ,
9799 );
98100 }
99101 }
@@ -121,7 +123,7 @@ function route(
121123 '/\{[^}]+\}/ ' ,
122124 $ param [$ i ],
123125 $ routes [$ name ],
124- 1
126+ 1 ,
125127 );
126128 } else {
127129 $ route = preg_replace ('/\{[^}]+\}/ ' , $ param [$ i ], $ route , 1 );
@@ -156,7 +158,7 @@ function asset(string $filename, string $path_type = RELATIVE_PATH): string
156158 $ self ,
157159 '/ ' ,
158160 strrpos ($ self , $ find ),
159- strlen ($ find )
161+ strlen ($ find ),
160162 );
161163 }
162164
@@ -175,6 +177,8 @@ function asset(string $filename, string $path_type = RELATIVE_PATH): string
175177 return $ path . $ filename ;
176178 case ABSOLUTE_PATH :
177179 return $ root_path . $ filename ;
180+ case REMOTE_PATH :
181+ return Application::$ REMOTE_ADDR . '/ ' . $ filename ;
178182 default :
179183 return $ filename ;
180184 }
@@ -206,7 +210,7 @@ function payload(
206210 array $ data ,
207211 int $ expires ,
208212 int $ issued_at = 0 ,
209- string $ issuer = ''
213+ string $ issuer = '' ,
210214): array {
211215 $ jwt = (new FileLoader ())
212216 ->load (__DIR__ . '/../Config/jwt.config.php ' )
@@ -223,9 +227,9 @@ function payload(
223227 [
224228 'iss ' => $ issuer ,
225229 'iat ' => $ issued_at ,
226- 'exp ' => $ expires
230+ 'exp ' => $ expires,
227231 ],
228- $ data
232+ $ data,
229233 );
230234}
231235
@@ -294,13 +298,21 @@ function ExceptionHandler(Throwable $exception)
294298 'Error: %s in %s on line %d ' ,
295299 $ exception ->getMessage (),
296300 $ file ,
297- $ line
301+ $ line,
298302 );
299303 }
300304
301305 // Log the detailed error message
302306 error_log ($ detailedMessage );
303307
308+ if ((new Request ())->isAjax ()) {
309+ echo json_encode ([
310+ 'exception ' => $ message ,
311+ 'file ' => $ file ,
312+ 'line ' => $ line ,
313+ ]);
314+ exit ();
315+ }
304316 include_once __DIR__ . '/../Exception/template/index.php ' ;
305317}
306318
0 commit comments