2
0

some block cleanup

This commit is contained in:
Sky Johnson 2025-09-10 21:40:01 -05:00
parent bb6fe3612b
commit dbbf3b8f4f
4 changed files with 11 additions and 32 deletions

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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');