Skip to content

Commit cad438d

Browse files
author
gingertek
committed
added method property to $req, updated docs
1 parent ba3ee0d commit cad438d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ There are 4 global variables you can use in a layout or page file: `$config`, `$
110110
|Name|Data Type|Note|
111111
|---|---|---|
112112
|`$config`|`object`|The stdClass object of `config.json`|
113-
|`$req`|`object`|The current request, contains properties `path` (string of URI), `query` (associative array of URL query parameters), and `params` (asociative array of dynamic URI parameters)|
113+
|`$req`|`object`|The current request, contains properties `path` (string of URI), `method` (string of HTTP method), `query` (associative array of URL query parameters), and `params` (asociative array of dynamic URI parameters)|
114114
|`$page`|`object`|Contains the `body` content property, as well as all the properties defined by the route object|
115115

116116
# Config.json

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function st(int $c) { http_response_code($c); exit; }
1616
$config = json_decode(file_get_contents('config.json'), false, 10, JSON_THROW_ON_ERROR);
1717
if ($config->maintenance) st(503);
1818
$req = (object)parse_url(rtrim($_SERVER['REQUEST_URI'], '/') ?: '/'); $req->query = $_REQUEST ?? []; $req->params = [];
19+
$req->method = $_SERVER['REQUEST_METHOD'];
1920
$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'} ?? st(404);
2021
if (file_exists('plugins')) { foreach (glob('plugins/*', GLOB_ONLYDIR) as $p) include "$p/" . basename($p) . '.php'; }
2122
if (property_exists($page, 'file') && file_exists($page->file)) { ob_start(); include $page->file; $page->body = ob_get_clean(); }

0 commit comments

Comments
 (0)