From dbbf3b8f4f1449328b1f1a5588d7a8cb6180a637 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 10 Sep 2025 21:40:01 -0500 Subject: [PATCH] some block cleanup --- request.php | 10 ++++------ response.php | 12 +++--------- session.php | 12 ++---------- web.php | 9 ++------- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/request.php b/request.php index 1dc139a..6d4f2c6 100644 --- a/request.php +++ b/request.php @@ -53,12 +53,10 @@ class Request $headers[strtolower($header)] = $value; } } - if (isset($_SERVER['CONTENT_TYPE'])) { - $headers['content-type'] = $_SERVER['CONTENT_TYPE']; - } - if (isset($_SERVER['CONTENT_LENGTH'])) { - $headers['content-length'] = $_SERVER['CONTENT_LENGTH']; - } + + if (isset($_SERVER['CONTENT_TYPE'])) $headers['content-type'] = $_SERVER['CONTENT_TYPE']; + if (isset($_SERVER['CONTENT_LENGTH'])) $headers['content-length'] = $_SERVER['CONTENT_LENGTH']; + return $headers; } diff --git a/response.php b/response.php index 744a72e..695d44f 100644 --- a/response.php +++ b/response.php @@ -102,15 +102,11 @@ class Response */ public function send(): void { - if ($this->sent) { - return; - } + if ($this->sent) return; http_response_code($this->statusCode); - foreach ($this->headers as $name => $value) { - header("$name: $value"); - } + foreach ($this->headers as $name => $value) header("$name: $value"); echo $this->body; $this->sent = true; @@ -130,9 +126,7 @@ class Response */ public function end(string $content = ''): void { - if ($content) { - $this->body .= $content; - } + if ($content) $this->body .= $content; $this->send(); } } diff --git a/session.php b/session.php index d38a88f..7e7daaf 100644 --- a/session.php +++ b/session.php @@ -91,11 +91,7 @@ class Session public function csrfToken(): string { $this->ensureStarted(); - - if (!isset($_SESSION['_csrf_token'])) { - $_SESSION['_csrf_token'] = bin2hex(random_bytes(32)); - } - + if (!isset($_SESSION['_csrf_token'])) $_SESSION['_csrf_token'] = bin2hex(random_bytes(32)); return $_SESSION['_csrf_token']; } @@ -105,11 +101,7 @@ class Session public function validateCsrf(string $token): bool { $this->ensureStarted(); - - if (!isset($_SESSION['_csrf_token'])) { - return false; - } - + if (!isset($_SESSION['_csrf_token'])) return false; return hash_equals($_SESSION['_csrf_token'], $token); } diff --git a/web.php b/web.php index 9656cff..44b0560 100644 --- a/web.php +++ b/web.php @@ -86,13 +86,9 @@ class Web private function addGroupRoutes(Router $router, string $prefix, string $path, mixed $node, string $currentPath = ''): void { - if ($path !== '') { - $currentPath = $currentPath ? "$currentPath/$path" : $path; - } + if ($path !== '') $currentPath = $currentPath ? "$currentPath/$path" : $path; - if (!is_array($node)) { - return; - } + if (!is_array($node)) return; foreach ($node as $key => $value) { if (in_array($key, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])) { @@ -154,7 +150,6 @@ class Web ); $chain(); - } catch (Exception $e) { error_log($e->getMessage()); $this->context->error(500, 'Internal Server Error');