@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | protected $template; |
23 | 23 | |
24 | - public function __construct (string $template, array $data = []) { |
|
24 | + public function __construct(string $template, array $data = []) { |
|
25 | 25 | $this->template = $template; |
26 | 26 | $this->data = $data; |
27 | 27 | } |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function __toString () { |
|
32 | + public function __toString() { |
|
33 | 33 | return $this->template; |
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public function getContent (): string { |
|
39 | + public function getContent(): string { |
|
40 | 40 | ob_start(); |
41 | 41 | $this->render(); |
42 | 42 | return ob_end_clean(); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param mixed $offset |
47 | 47 | * @return bool |
48 | 48 | */ |
49 | - public function offsetExists ($offset): bool { |
|
49 | + public function offsetExists($offset): bool { |
|
50 | 50 | return isset($this->data[$offset]); |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param mixed $key |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public function offsetGet ($key) { |
|
57 | + public function offsetGet($key) { |
|
58 | 58 | return $this->data[$key] ?? null; |
59 | 59 | } |
60 | 60 | |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * @param mixed $key |
63 | 63 | * @param mixed $value |
64 | 64 | */ |
65 | - public function offsetSet ($key, $value): void { |
|
65 | + public function offsetSet($key, $value): void { |
|
66 | 66 | $this->data[$key] = $value; |
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @param mixed $key |
71 | 71 | */ |
72 | - public function offsetUnset ($key): void { |
|
72 | + public function offsetUnset($key): void { |
|
73 | 73 | unset($this->data[$key]); |
74 | 74 | } |
75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function render (): void { |
|
82 | + public function render(): void { |
|
83 | 83 | extract($this->data); |
84 | 84 | include "{$this->template}"; |
85 | 85 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function getContent (): string; |
|
15 | + public function getContent(): string; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Directly outputs content. |
19 | 19 | */ |
20 | - public function render (): void; |
|
20 | + public function render(): void; |
|
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @param Site $site |
55 | 55 | */ |
56 | - public function __construct (Site $site) { |
|
56 | + public function __construct(Site $site) { |
|
57 | 57 | $this->site = $site; |
58 | 58 | $this->request = $site->getRequest(); |
59 | 59 | $this->id = uniqid(); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - public function _onRender (): void { |
|
74 | + public function _onRender(): void { |
|
75 | 75 | header_remove('X-Powered-By'); |
76 | 76 | $this['X-Response-Id'] = $this->id; |
77 | 77 | ksort($this->headers); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return void |
98 | 98 | */ |
99 | - public function _onShutdown (): void { |
|
99 | + public function _onShutdown(): void { |
|
100 | 100 | if ($this->site->isDev()) { |
101 | 101 | $ip = $this->request->getClient(); |
102 | 102 | $method = $this->request->getMethod(); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param Throwable $error Defaults to an `Error` with the current response code. |
116 | 116 | */ |
117 | - public function error (Throwable $error = null): void { |
|
117 | + public function error(Throwable $error = null): void { |
|
118 | 118 | $error = $error ?? new Error($this->code); |
119 | 119 | $code = 500; |
120 | 120 | if ($error instanceof Error) { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @param string $path |
142 | 142 | * @param bool $download |
143 | 143 | */ |
144 | - public function file (string $path, bool $download = false): void { |
|
144 | + public function file(string $path, bool $download = false): void { |
|
145 | 145 | clearstatcache(true, $path); |
146 | 146 | if (!file_exists($path)) { |
147 | 147 | $this->setCode(404)->error() and exit; |
@@ -196,21 +196,21 @@ discard block |
||
196 | 196 | /** |
197 | 197 | * @return int |
198 | 198 | */ |
199 | - final public function getCode (): int { |
|
199 | + final public function getCode(): int { |
|
200 | 200 | return $this->code; |
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - final public function getId (): string { |
|
206 | + final public function getId(): string { |
|
207 | 207 | return $this->id; |
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @return int |
212 | 212 | */ |
213 | - public function getTimestamp (): int { |
|
213 | + public function getTimestamp(): int { |
|
214 | 214 | return $this->timestamp; |
215 | 215 | } |
216 | 216 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return bool |
221 | 221 | */ |
222 | - public function isEmpty (): bool { |
|
222 | + public function isEmpty(): bool { |
|
223 | 223 | return $this->request->isHead() or in_array($this->code, [204, 205, 304]); |
224 | 224 | } |
225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return bool |
230 | 230 | */ |
231 | - public function isModified (): bool { |
|
231 | + public function isModified(): bool { |
|
232 | 232 | // Explicit 304 takes precedence over all. |
233 | 233 | if ($this->code === 304) { |
234 | 234 | return false; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @param mixed $content |
250 | 250 | */ |
251 | - public function mixed ($content): void { |
|
251 | + public function mixed($content): void { |
|
252 | 252 | if ($content instanceof ViewableInterface) { |
253 | 253 | $this->view($content) and exit; |
254 | 254 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param mixed $key |
265 | 265 | * @return bool |
266 | 266 | */ |
267 | - public function offsetExists ($key) { |
|
267 | + public function offsetExists($key) { |
|
268 | 268 | return isset($this->headers[$key]); |
269 | 269 | } |
270 | 270 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param mixed $key |
273 | 273 | * @return null|string |
274 | 274 | */ |
275 | - public function offsetGet ($key) { |
|
275 | + public function offsetGet($key) { |
|
276 | 276 | return $this->headers[$key] ?? null; |
277 | 277 | } |
278 | 278 | |
@@ -280,14 +280,14 @@ discard block |
||
280 | 280 | * @param mixed $key |
281 | 281 | * @param string $value |
282 | 282 | */ |
283 | - public function offsetSet ($key, $value) { |
|
283 | + public function offsetSet($key, $value) { |
|
284 | 284 | $this->headers[$key] = $value; |
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * @param mixed $key |
289 | 289 | */ |
290 | - public function offsetUnset ($key) { |
|
290 | + public function offsetUnset($key) { |
|
291 | 291 | unset($this->headers[$key]); |
292 | 292 | } |
293 | 293 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @param string $location |
298 | 298 | * @param int $code |
299 | 299 | */ |
300 | - public function redirect (string $location, $code = 302) { |
|
300 | + public function redirect(string $location, $code = 302) { |
|
301 | 301 | $this->setCode($code); |
302 | 302 | $this['Location'] = $location; |
303 | 303 | flush(); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @param int $code |
309 | 309 | * @return $this |
310 | 310 | */ |
311 | - public function setCode (int $code) { |
|
311 | + public function setCode(int $code) { |
|
312 | 312 | $this->code = $code; |
313 | 313 | return $this; |
314 | 314 | } |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param int $timestamp |
320 | 320 | * @return $this |
321 | 321 | */ |
322 | - public function setTimestamp (int $timestamp) { |
|
322 | + public function setTimestamp(int $timestamp) { |
|
323 | 323 | if ($timestamp) { |
324 | 324 | $this['Last-Modified'] = gmdate('D, d M Y H:i:s T', $timestamp); |
325 | 325 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * @param int $timestamp |
337 | 337 | * @return $this |
338 | 338 | */ |
339 | - public function touch (int $timestamp) { |
|
339 | + public function touch(int $timestamp) { |
|
340 | 340 | if ($timestamp > $this->timestamp) { |
341 | 341 | $this->setTimestamp($timestamp); |
342 | 342 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * |
349 | 349 | * @param ViewableInterface $view |
350 | 350 | */ |
351 | - public function view (ViewableInterface $view): void { |
|
351 | + public function view(ViewableInterface $view): void { |
|
352 | 352 | $view->render(); |
353 | 353 | flush(); |
354 | 354 | exit; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected $proxies = []; |
50 | 50 | |
51 | - public function __construct () { |
|
51 | + public function __construct() { |
|
52 | 52 | $this->path = Util::path(urldecode(strtok($_SERVER['REQUEST_URI'], '?'))); |
53 | 53 | $this->headers = array_change_key_case(getallheaders()); // phpstorm bug submitted, ext-apache isn't needed. |
54 | 54 | foreach ($_FILES as $name => $info) { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - final public function __toString () { |
|
78 | + final public function __toString() { |
|
79 | 79 | return $this->path; |
80 | 80 | } |
81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return array |
86 | 86 | */ |
87 | - public function getArgs (): array { |
|
87 | + public function getArgs(): array { |
|
88 | 88 | return array_merge($_GET, $_POST); |
89 | 89 | } |
90 | 90 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public function getClient () { |
|
96 | + public function getClient() { |
|
97 | 97 | if (in_array($_SERVER['REMOTE_ADDR'], $this->proxies)) { |
98 | 98 | return $this['X-Forwarded-For'] ?? $_SERVER['REMOTE_ADDR']; |
99 | 99 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string $name |
105 | 105 | * @return null|Upload |
106 | 106 | */ |
107 | - final public function getFile (string $name) { |
|
107 | + final public function getFile(string $name) { |
|
108 | 108 | return $this->files[$name] ?? null; |
109 | 109 | } |
110 | 110 | |
@@ -112,70 +112,70 @@ discard block |
||
112 | 112 | * @param string $name |
113 | 113 | * @return Upload[] |
114 | 114 | */ |
115 | - final public function getFileGroup (string $name) { |
|
115 | + final public function getFileGroup(string $name) { |
|
116 | 116 | return $this->fileGroups[$name] ?? []; |
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @return Upload[][] |
121 | 121 | */ |
122 | - final public function getFileGroups () { |
|
122 | + final public function getFileGroups() { |
|
123 | 123 | return $this->fileGroups; |
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @return Upload[] |
128 | 128 | */ |
129 | - final public function getFiles () { |
|
129 | + final public function getFiles() { |
|
130 | 130 | return $this->files; |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return string[] |
135 | 135 | */ |
136 | - public function getHeaders (): array { |
|
136 | + public function getHeaders(): array { |
|
137 | 137 | return $this->headers; |
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - final public function getMethod (): string { |
|
143 | + final public function getMethod(): string { |
|
144 | 144 | return $_SERVER['REQUEST_METHOD']; |
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - final public function getPath (): string { |
|
150 | + final public function getPath(): string { |
|
151 | 151 | return $this->path; |
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @return string[] |
156 | 156 | */ |
157 | - public function getProxies (): array { |
|
157 | + public function getProxies(): array { |
|
158 | 158 | return $this->proxies; |
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @return bool |
163 | 163 | */ |
164 | - final public function isDelete (): bool { |
|
164 | + final public function isDelete(): bool { |
|
165 | 165 | return $_SERVER['REQUEST_METHOD'] === 'DELETE'; |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @return bool |
170 | 170 | */ |
171 | - final public function isGet (): bool { |
|
171 | + final public function isGet(): bool { |
|
172 | 172 | return $_SERVER['REQUEST_METHOD'] === 'GET'; |
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | 176 | * @return bool |
177 | 177 | */ |
178 | - final public function isHead (): bool { |
|
178 | + final public function isHead(): bool { |
|
179 | 179 | return $_SERVER['REQUEST_METHOD'] === 'HEAD'; |
180 | 180 | } |
181 | 181 | |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return bool |
186 | 186 | */ |
187 | - final public function isMuting (): bool { |
|
187 | + final public function isMuting(): bool { |
|
188 | 188 | return !$this->isGet() and !$this->isHead(); |
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - final public function isPost (): bool { |
|
194 | + final public function isPost(): bool { |
|
195 | 195 | return $_SERVER['REQUEST_METHOD'] === 'POST'; |
196 | 196 | } |
197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param string $key |
202 | 202 | * @return bool |
203 | 203 | */ |
204 | - public function offsetExists ($key) { |
|
204 | + public function offsetExists($key) { |
|
205 | 205 | return isset($this->headers[strtolower($key)]); |
206 | 206 | } |
207 | 207 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param string $key |
212 | 212 | * @return null|string |
213 | 213 | */ |
214 | - public function offsetGet ($key) { |
|
214 | + public function offsetGet($key) { |
|
215 | 215 | return $this->headers[strtolower($key)] ?? null; |
216 | 216 | } |
217 | 217 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param mixed $key |
222 | 222 | * @param mixed $value |
223 | 223 | */ |
224 | - public function offsetSet ($key, $value) { |
|
224 | + public function offsetSet($key, $value) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @param mixed $key |
232 | 232 | */ |
233 | - public function offsetUnset ($key) { |
|
233 | + public function offsetUnset($key) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param string[] $proxies |
239 | 239 | * @return $this |
240 | 240 | */ |
241 | - public function setProxies (array $proxies) { |
|
241 | + public function setProxies(array $proxies) { |
|
242 | 242 | $this->proxies = $proxies; |
243 | 243 | return $this; |
244 | 244 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Initializes the system for routing, error handling, and output. |
39 | 39 | */ |
40 | - public function __construct () { |
|
40 | + public function __construct() { |
|
41 | 41 | error_reporting(E_ALL); |
42 | 42 | set_error_handler([$this, '_onRaise']); |
43 | 43 | $this->request = new Request(); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param Throwable $error |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function _onException (Throwable $error): void { |
|
56 | + public function _onException(Throwable $error): void { |
|
57 | 57 | if (!$error instanceof Error) { |
58 | 58 | $this->log(500, "[{$error->getCode()}] {$error}"); |
59 | 59 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param int $line |
74 | 74 | * @throws ErrorException |
75 | 75 | */ |
76 | - public function _onRaise (int $code, string $message, string $file, int $line) { |
|
76 | + public function _onRaise(int $code, string $message, string $file, int $line) { |
|
77 | 77 | $type = [ |
78 | 78 | E_DEPRECATED => 'E_DEPRECATED', |
79 | 79 | E_NOTICE => 'E_NOTICE', |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param callable $controller |
98 | 98 | * @return void |
99 | 99 | */ |
100 | - public function delete (string $path, callable $controller): void { |
|
100 | + public function delete(string $path, callable $controller): void { |
|
101 | 101 | $this->route(['DELETE'], $path, $controller); |
102 | 102 | } |
103 | 103 | |
@@ -108,35 +108,35 @@ discard block |
||
108 | 108 | * @param callable $controller |
109 | 109 | * @return void |
110 | 110 | */ |
111 | - public function get (string $path, callable $controller): void { |
|
111 | + public function get(string $path, callable $controller): void { |
|
112 | 112 | $this->route(['GET', 'HEAD'], $path, $controller); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return Auth |
117 | 117 | */ |
118 | - final public function getAuth () { |
|
118 | + final public function getAuth() { |
|
119 | 119 | return $this->auth ?? $this->auth = new Auth($this); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @return Request |
124 | 124 | */ |
125 | - final public function getRequest () { |
|
125 | + final public function getRequest() { |
|
126 | 126 | return $this->request; |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @return Response |
131 | 131 | */ |
132 | - final public function getResponse () { |
|
132 | + final public function getResponse() { |
|
133 | 133 | return $this->response; |
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @return bool |
138 | 138 | */ |
139 | - final public function isDev (): bool { |
|
139 | + final public function isDev(): bool { |
|
140 | 140 | return $this->dev; |
141 | 141 | } |
142 | 142 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param string $message |
146 | 146 | * @return $this |
147 | 147 | */ |
148 | - public function log ($code, string $message) { |
|
148 | + public function log($code, string $message) { |
|
149 | 149 | $now = date('Y-m-d H:i:s'); |
150 | 150 | $id = $this->response->getId(); |
151 | 151 | $ip = $this->request->getClient(); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string $path |
163 | 163 | * @param callable $controller |
164 | 164 | */ |
165 | - public function post (string $path, callable $controller): void { |
|
165 | + public function post(string $path, callable $controller): void { |
|
166 | 166 | $this->route(['POST'], $path, $controller); |
167 | 167 | } |
168 | 168 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @param callable $controller |
174 | 174 | * @return void |
175 | 175 | */ |
176 | - public function put (string $path, callable $controller): void { |
|
176 | + public function put(string $path, callable $controller): void { |
|
177 | 177 | $this->route(['PUT'], $path, $controller); |
178 | 178 | } |
179 | 179 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param callable $controller `(string[] $match, Site $site):mixed` |
187 | 187 | * @return void |
188 | 188 | */ |
189 | - protected function route (array $methods, string $path, callable $controller): void { |
|
189 | + protected function route(array $methods, string $path, callable $controller): void { |
|
190 | 190 | $match = []; |
191 | 191 | if ($path[0] !== '/') { |
192 | 192 | preg_match($path, $this->request->getPath(), $match); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param bool $dev |
209 | 209 | * @return $this |
210 | 210 | */ |
211 | - public function setDev (bool $dev) { |
|
211 | + public function setDev(bool $dev) { |
|
212 | 212 | $this->dev = $dev; |
213 | 213 | return $this; |
214 | 214 | } |