@@ -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()); |
| 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 | } |
@@ -61,8 +61,7 @@ |
||
| 61 | 61 | $info['tmp_name'][$i] |
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | - } |
|
| 65 | - else { |
|
| 64 | + } else { |
|
| 66 | 65 | $this->files[$name] = new Upload( |
| 67 | 66 | $info['error_code'], |
| 68 | 67 | $info['name'], |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | - public function buffer (): string; |
|
| 15 | + public function buffer(): 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 | } |
| 23 | 23 | \ No newline at end of file |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @param Site $site |
| 22 | 22 | */ |
| 23 | - public function __construct (Site $site) { |
|
| 23 | + public function __construct(Site $site) { |
|
| 24 | 24 | $this->site = $site; |
| 25 | 25 | session_set_cookie_params(0, '/', null, !$site->isDev(), true); |
| 26 | 26 | session_start(); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function getToken (): string { |
|
| 40 | + public function getToken(): string { |
|
| 41 | 41 | return $_SESSION['_token']; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return mixed |
| 48 | 48 | */ |
| 49 | - public function getUser () { |
|
| 49 | + public function getUser() { |
|
| 50 | 50 | return $_SESSION['_user'] ?? null; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Wipes the session. |
| 55 | 55 | */ |
| 56 | - public function logout () { |
|
| 56 | + public function logout() { |
|
| 57 | 57 | setcookie(session_name(), null, 1); |
| 58 | 58 | session_destroy(); |
| 59 | 59 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param mixed $user |
| 65 | 65 | * @return $this |
| 66 | 66 | */ |
| 67 | - public function setUser ($user) { |
|
| 67 | + public function setUser($user) { |
|
| 68 | 68 | $_SESSION['_user'] = $user; |
| 69 | 69 | return $this; |
| 70 | 70 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @return $this |
| 78 | 78 | * @throws Error |
| 79 | 79 | */ |
| 80 | - public function verify ($token) { |
|
| 80 | + public function verify($token) { |
|
| 81 | 81 | if ($token !== $this->getToken()) { |
| 82 | 82 | $this->site->log(403, 'Invalid token.'); |
| 83 | 83 | throw new Error(403, 'Invalid token.'); |
@@ -27,8 +27,7 @@ |
||
| 27 | 27 | if (!isset($_SESSION['_token'])) { |
| 28 | 28 | try { |
| 29 | 29 | $_SESSION['_token'] = bin2hex(random_bytes(8)); |
| 30 | - } |
|
| 31 | - catch (Exception $exception) { |
|
| 30 | + } catch (Exception $exception) { |
|
| 32 | 31 | $_SESSION['_token'] = bin2hex(openssl_random_pseudo_bytes(8)); |
| 33 | 32 | } |
| 34 | 33 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param string $message Defaults to the standard description. |
| 54 | 54 | * @param Throwable|null $previous |
| 55 | 55 | */ |
| 56 | - public function __construct (int $code, string $message = null, Throwable $previous = null) { |
|
| 56 | + public function __construct(int $code, string $message = null, Throwable $previous = null) { |
|
| 57 | 57 | $message = $message ?? self::MESSAGES[$code] ?? ''; |
| 58 | 58 | parent::__construct($message, $code, $previous); |
| 59 | 59 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | protected $template; |
| 21 | 21 | |
| 22 | - public function __construct (string $template, array $data = []) { |
|
| 22 | + public function __construct(string $template, array $data = []) { |
|
| 23 | 23 | $this->template = $template; |
| 24 | 24 | $this->data = $data; |
| 25 | 25 | } |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public function __toString () { |
|
| 30 | + public function __toString() { |
|
| 31 | 31 | return $this->template; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | - public function buffer (): string { |
|
| 37 | + public function buffer(): string { |
|
| 38 | 38 | ob_start(); |
| 39 | 39 | $this->render(); |
| 40 | 40 | return ob_end_clean(); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param mixed $offset |
| 45 | 45 | * @return bool |
| 46 | 46 | */ |
| 47 | - public function offsetExists ($offset): bool { |
|
| 47 | + public function offsetExists($offset): bool { |
|
| 48 | 48 | return isset($this->data[$offset]); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param mixed $key |
| 53 | 53 | * @return mixed |
| 54 | 54 | */ |
| 55 | - public function offsetGet ($key) { |
|
| 55 | + public function offsetGet($key) { |
|
| 56 | 56 | return $this->data[$key] ?? null; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | * @param mixed $key |
| 61 | 61 | * @param mixed $value |
| 62 | 62 | */ |
| 63 | - public function offsetSet ($key, $value): void { |
|
| 63 | + public function offsetSet($key, $value): void { |
|
| 64 | 64 | $this->data[$key] = $value; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @param mixed $key |
| 69 | 69 | */ |
| 70 | - public function offsetUnset ($key): void { |
|
| 70 | + public function offsetUnset($key): void { |
|
| 71 | 71 | unset($this->data[$key]); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return void |
| 79 | 79 | */ |
| 80 | - public function render (): void { |
|
| 80 | + public function render(): void { |
|
| 81 | 81 | include "{$this->template}"; |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | \ No newline at end of file |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @param Site $site |
| 54 | 54 | */ |
| 55 | - public function __construct (Site $site) { |
|
| 55 | + public function __construct(Site $site) { |
|
| 56 | 56 | $this->site = $site; |
| 57 | 57 | $this->request = $site->getRequest(); |
| 58 | 58 | $this->id = uniqid(); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param Throwable $error Defaults to an `Error` with the current response code. |
| 69 | 69 | */ |
| 70 | - public function error (Throwable $error = null) { |
|
| 70 | + public function error(Throwable $error = null) { |
|
| 71 | 71 | $error = $error ?? new Error($this->code); |
| 72 | 72 | $code = 500; |
| 73 | 73 | if ($error instanceof Error) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param string $path |
| 94 | 94 | * @param bool $download |
| 95 | 95 | */ |
| 96 | - public function file (string $path, bool $download = false) { |
|
| 96 | + public function file(string $path, bool $download = false) { |
|
| 97 | 97 | if (!file_exists($path)) { |
| 98 | 98 | return $this->setCode(404)->error(); |
| 99 | 99 | } |
@@ -147,21 +147,21 @@ discard block |
||
| 147 | 147 | /** |
| 148 | 148 | * @return int |
| 149 | 149 | */ |
| 150 | - final public function getCode (): int { |
|
| 150 | + final public function getCode(): int { |
|
| 151 | 151 | return $this->code; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * @return string |
| 156 | 156 | */ |
| 157 | - final public function getId (): string { |
|
| 157 | + final public function getId(): string { |
|
| 158 | 158 | return $this->id; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * @return int |
| 163 | 163 | */ |
| 164 | - public function getTimestamp (): int { |
|
| 164 | + public function getTimestamp(): int { |
|
| 165 | 165 | return $this->timestamp; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return bool |
| 172 | 172 | */ |
| 173 | - public function isEmpty (): bool { |
|
| 173 | + public function isEmpty(): bool { |
|
| 174 | 174 | return $this->request->isHead() or in_array($this->code, [204, 205, 304]); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | - public function isModified (): bool { |
|
| 182 | + public function isModified(): bool { |
|
| 183 | 183 | // Explicit 304 takes precedence over all. |
| 184 | 184 | if ($this->code === 304) { |
| 185 | 185 | return false; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @param mixed $content |
| 201 | 201 | */ |
| 202 | - public function mixed ($content) { |
|
| 202 | + public function mixed($content) { |
|
| 203 | 203 | if ($content instanceof ViewableInterface) { |
| 204 | 204 | return $this->view($content); |
| 205 | 205 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @param mixed $key |
| 216 | 216 | * @return bool |
| 217 | 217 | */ |
| 218 | - public function offsetExists ($key) { |
|
| 218 | + public function offsetExists($key) { |
|
| 219 | 219 | return isset($this->headers[$key]); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param mixed $key |
| 224 | 224 | * @return null|string |
| 225 | 225 | */ |
| 226 | - public function offsetGet ($key) { |
|
| 226 | + public function offsetGet($key) { |
|
| 227 | 227 | return $this->headers[$key] ?? null; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * @param mixed $key |
| 232 | 232 | * @param string $value |
| 233 | 233 | */ |
| 234 | - public function offsetSet ($key, $value) { |
|
| 234 | + public function offsetSet($key, $value) { |
|
| 235 | 235 | $this->headers[$key] = $value; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * @param mixed $key |
| 240 | 240 | */ |
| 241 | - public function offsetUnset ($key) { |
|
| 241 | + public function offsetUnset($key) { |
|
| 242 | 242 | unset($this->headers[$key]); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @return void |
| 250 | 250 | */ |
| 251 | - public function onExit (): void { |
|
| 251 | + public function onExit(): void { |
|
| 252 | 252 | if ($this->site->isDev()) { |
| 253 | 253 | $ip = $this->request->getClient(); |
| 254 | 254 | $method = $this->request->getMethod(); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public function onRender (): void { |
|
| 270 | + public function onRender(): void { |
|
| 271 | 271 | $this['X-Response-Id'] = $this->id; |
| 272 | 272 | foreach ($this->headers as $key => $value) { |
| 273 | 273 | if (is_string($key)) { |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @param string $location |
| 292 | 292 | * @param int $code |
| 293 | 293 | */ |
| 294 | - public function redirect (string $location, $code = 302) { |
|
| 294 | + public function redirect(string $location, $code = 302) { |
|
| 295 | 295 | $this->setCode($code); |
| 296 | 296 | $this['Location'] = $location; |
| 297 | 297 | flush(); // empty body |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param int $code |
| 303 | 303 | * @return $this |
| 304 | 304 | */ |
| 305 | - public function setCode (int $code) { |
|
| 305 | + public function setCode(int $code) { |
|
| 306 | 306 | $this->code = $code; |
| 307 | 307 | return $this; |
| 308 | 308 | } |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * @param int $timestamp |
| 314 | 314 | * @return $this |
| 315 | 315 | */ |
| 316 | - public function setTimestamp (int $timestamp) { |
|
| 316 | + public function setTimestamp(int $timestamp) { |
|
| 317 | 317 | if ($timestamp) { |
| 318 | 318 | $this['Last-Modified'] = gmdate('D, d M Y H:i:s T', $timestamp); |
| 319 | 319 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @param int $timestamp |
| 331 | 331 | * @return $this |
| 332 | 332 | */ |
| 333 | - public function touch (int $timestamp) { |
|
| 333 | + public function touch(int $timestamp) { |
|
| 334 | 334 | if ($timestamp > $this->timestamp) { |
| 335 | 335 | $this->setTimestamp($timestamp); |
| 336 | 336 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | * @param ViewableInterface $view |
| 344 | 344 | */ |
| 345 | - public function view (ViewableInterface $view) { |
|
| 345 | + public function view(ViewableInterface $view) { |
|
| 346 | 346 | flush(); // possible empty body |
| 347 | 347 | $view->render(); |
| 348 | 348 | exit; |
@@ -77,8 +77,7 @@ discard block |
||
| 77 | 77 | $template = __DIR__ . '/error.phtml'; |
| 78 | 78 | if (file_exists("view/{$code}.phtml")) { |
| 79 | 79 | $template = "view/{$code}.phtml"; |
| 80 | - } |
|
| 81 | - elseif (file_exists('view/error.phtml')) { |
|
| 80 | + } elseif (file_exists('view/error.phtml')) { |
|
| 82 | 81 | $template = 'view/error.phtml'; |
| 83 | 82 | } |
| 84 | 83 | return $this->view(new View($template, [ |
@@ -316,8 +315,7 @@ discard block |
||
| 316 | 315 | public function setTimestamp (int $timestamp) { |
| 317 | 316 | if ($timestamp) { |
| 318 | 317 | $this['Last-Modified'] = gmdate('D, d M Y H:i:s T', $timestamp); |
| 319 | - } |
|
| 320 | - else { |
|
| 318 | + } else { |
|
| 321 | 319 | unset($this['Last-Modified']); |
| 322 | 320 | } |
| 323 | 321 | $this->timestamp = $timestamp; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * @param string[] $args |
| 14 | 14 | * @return string |
| 15 | 15 | */ |
| 16 | - public static function path (...$args): string { |
|
| 16 | + public static function path(...$args): string { |
|
| 17 | 17 | $path = trim(implode('/', $args), '/'); |
| 18 | 18 | $path = preg_replace('/\/+/', '/', $path); |
| 19 | 19 | return '/' . $path; |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param string[] $args |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - public static function slug (...$args): string { |
|
| 28 | + public static function slug(...$args): string { |
|
| 29 | 29 | $slug = strtolower(implode('-', $args)); |
| 30 | 30 | $slug = preg_replace('/([^a-z0-9]+)/', '-', $slug); |
| 31 | 31 | $slug = preg_replace('/-+/', '-', $slug); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param string $remoteName |
| 34 | 34 | * @param string $path |
| 35 | 35 | */ |
| 36 | - public function __construct (int $status, string $remoteName, string $path) { |
|
| 36 | + public function __construct(int $status, string $remoteName, string $path) { |
|
| 37 | 37 | $this->status = $status; |
| 38 | 38 | $this->remoteName = $remoteName; |
| 39 | 39 | $this->path = $path; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return null|Error |
| 46 | 46 | */ |
| 47 | - public function getError () { |
|
| 47 | + public function getError() { |
|
| 48 | 48 | switch ($this->status) { |
| 49 | 49 | case UPLOAD_ERR_INI_SIZE: |
| 50 | 50 | case UPLOAD_ERR_FORM_SIZE: |
@@ -67,35 +67,35 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | - final public function getPath (): string { |
|
| 70 | + final public function getPath(): string { |
|
| 71 | 71 | return $this->path; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - final public function getRemoteName (): string { |
|
| 77 | + final public function getRemoteName(): string { |
|
| 78 | 78 | return $this->remoteName; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @return int |
| 83 | 83 | */ |
| 84 | - final public function getSize (): int { |
|
| 84 | + final public function getSize(): int { |
|
| 85 | 85 | return filesize($this->path); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @return int |
| 90 | 90 | */ |
| 91 | - final public function getStatus (): int { |
|
| 91 | + final public function getStatus(): int { |
|
| 92 | 92 | return $this->status; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - final public function getType (): string { |
|
| 98 | + final public function getType(): string { |
|
| 99 | 99 | return mime_content_type($this->path); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string $path |
| 104 | 104 | * @return $this |
| 105 | 105 | */ |
| 106 | - public function move (string $path) { |
|
| 106 | + public function move(string $path) { |
|
| 107 | 107 | move_uploaded_file($this->path, $path); |
| 108 | 108 | return $this; |
| 109 | 109 | } |
@@ -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(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param callable $controller |
| 55 | 55 | * @return void |
| 56 | 56 | */ |
| 57 | - public function delete (string $path, callable $controller): void { |
|
| 57 | + public function delete(string $path, callable $controller): void { |
|
| 58 | 58 | $this->route(['DELETE'], $path, $controller); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -65,35 +65,35 @@ discard block |
||
| 65 | 65 | * @param callable $controller |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public function get (string $path, callable $controller): void { |
|
| 68 | + public function get(string $path, callable $controller): void { |
|
| 69 | 69 | $this->route(['GET', 'HEAD'], $path, $controller); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * @return Auth |
| 74 | 74 | */ |
| 75 | - final public function getAuth () { |
|
| 75 | + final public function getAuth() { |
|
| 76 | 76 | return $this->auth ?? $this->auth = new Auth($this); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * @return Request |
| 81 | 81 | */ |
| 82 | - final public function getRequest () { |
|
| 82 | + final public function getRequest() { |
|
| 83 | 83 | return $this->request; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * @return Response |
| 88 | 88 | */ |
| 89 | - final public function getResponse () { |
|
| 89 | + final public function getResponse() { |
|
| 90 | 90 | return $this->response; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - final public function isDev (): bool { |
|
| 96 | + final public function isDev(): bool { |
|
| 97 | 97 | return $this->dev; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @param string $message |
| 103 | 103 | * @return $this |
| 104 | 104 | */ |
| 105 | - public function log ($code, string $message) { |
|
| 105 | + public function log($code, string $message) { |
|
| 106 | 106 | $datetime = date('Y-m-d H:i:s'); |
| 107 | 107 | $id = $this->response->getId(); |
| 108 | 108 | $ip = $this->request->getClient(); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param Throwable $error |
| 120 | 120 | * @return void |
| 121 | 121 | */ |
| 122 | - public function onException (Throwable $error): void { |
|
| 122 | + public function onException(Throwable $error): void { |
|
| 123 | 123 | if (!$error instanceof Error) { |
| 124 | 124 | $this->log(500, "[{$error->getCode()}] {$error}"); |
| 125 | 125 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param int $line |
| 140 | 140 | * @throws ErrorException |
| 141 | 141 | */ |
| 142 | - public function onRaise (int $code, string $message, string $file, int $line) { |
|
| 142 | + public function onRaise(int $code, string $message, string $file, int $line) { |
|
| 143 | 143 | $type = [ |
| 144 | 144 | E_DEPRECATED => 'E_DEPRECATED', |
| 145 | 145 | E_NOTICE => 'E_NOTICE', |
@@ -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 | - public function route (array $methods, string $path, callable $controller): void { |
|
| 189 | + public 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 | } |
@@ -122,8 +122,7 @@ discard block |
||
| 122 | 122 | public function onException (Throwable $error): void { |
| 123 | 123 | if (!$error instanceof Error) { |
| 124 | 124 | $this->log(500, "[{$error->getCode()}] {$error}"); |
| 125 | - } |
|
| 126 | - elseif ($error->getCode() >= 500) { |
|
| 125 | + } elseif ($error->getCode() >= 500) { |
|
| 127 | 126 | $this->log($error->getCode(), $error); |
| 128 | 127 | } |
| 129 | 128 | $this->response->error($error); // exits |
@@ -190,8 +189,7 @@ discard block |
||
| 190 | 189 | $match = []; |
| 191 | 190 | if ($path[0] !== '/') { |
| 192 | 191 | preg_match($path, $this->request->getPath(), $match); |
| 193 | - } |
|
| 194 | - elseif ($path === $this->request->getPath()) { |
|
| 192 | + } elseif ($path === $this->request->getPath()) { |
|
| 195 | 193 | $match = [$path]; |
| 196 | 194 | } |
| 197 | 195 | if ($match) { |