Skip to content

Commit 35067af

Browse files
author
ginger-tek
committed
cast query and params to objects for simpler access syntax
1 parent 1fc1c92 commit 35067af

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ function sc(int $c) { http_response_code($c); exit; }
1616
if (!file_exists('config.json')) throw new \JerpyException('Missing config file');
1717
$config = json_decode(file_get_contents('config.json'), false, 10, JSON_THROW_ON_ERROR);
1818
if ($config->maintenance) sc(503);
19-
$req = (object)parse_url(rtrim($_SERVER['REQUEST_URI'], '/') ?: '/'); $req->query = $_REQUEST ?? []; $req->params = [];
19+
$req = (object)parse_url(rtrim($_SERVER['REQUEST_URI'], '/') ?: '/');
2020
$req->method = $_SERVER['REQUEST_METHOD'];
21-
$page = $config->routes->{$req->path} ?? $config->routes->{@array_values(array_filter(array_keys(get_object_vars($config->routes)), function($r) use($req) { if (preg_match('#^' . preg_replace('#:(\w+)#', '(?<$1>[\w\-\+\%]+)', $r) . '$#', $req->path, $params)) { $req->params = $params; return true; } return false; }))[0]} ?? $config->routes->{'404'} ?? sc(404);
21+
$req->query = (object)($_REQUEST ?? []); $req->params = (object)[];
22+
$page = $config->routes->{$req->path} ?? $config->routes->{@array_values(array_filter(array_keys(get_object_vars($config->routes)), function($r) use($req) { if (preg_match('#^' . preg_replace('#:(\w+)#', '(?<$1>[\w\-\+\%]+)', $r) . '$#', $req->path, $params)) { $req->params = (object)$params; return true; } return false; }))[0]} ?? $config->routes->{'404'} ?? sc(404);
2223
if (file_exists('plugins')) { foreach (glob('plugins/*', GLOB_ONLYDIR) as $p) include "$p/" . basename($p) . '.php'; }
2324
if (property_exists($page, 'file') && file_exists($page->file)) { ob_start(); include $page->file; $page->body = ob_get_clean(); }
2425
else if (!property_exists($page, 'body')) throw new \JerpyException('Route missing file and body property');

0 commit comments

Comments
 (0)