some block cleanup
This commit is contained in:
parent
bb6fe3612b
commit
dbbf3b8f4f
10
request.php
10
request.php
@ -53,12 +53,10 @@ class Request
|
|||||||
$headers[strtolower($header)] = $value;
|
$headers[strtolower($header)] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($_SERVER['CONTENT_TYPE'])) {
|
|
||||||
$headers['content-type'] = $_SERVER['CONTENT_TYPE'];
|
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_LENGTH'])) {
|
|
||||||
$headers['content-length'] = $_SERVER['CONTENT_LENGTH'];
|
|
||||||
}
|
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
response.php
12
response.php
@ -102,15 +102,11 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function send(): void
|
public function send(): void
|
||||||
{
|
{
|
||||||
if ($this->sent) {
|
if ($this->sent) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
http_response_code($this->statusCode);
|
http_response_code($this->statusCode);
|
||||||
|
|
||||||
foreach ($this->headers as $name => $value) {
|
foreach ($this->headers as $name => $value) header("$name: $value");
|
||||||
header("$name: $value");
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $this->body;
|
echo $this->body;
|
||||||
$this->sent = true;
|
$this->sent = true;
|
||||||
@ -130,9 +126,7 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function end(string $content = ''): void
|
public function end(string $content = ''): void
|
||||||
{
|
{
|
||||||
if ($content) {
|
if ($content) $this->body .= $content;
|
||||||
$this->body .= $content;
|
|
||||||
}
|
|
||||||
$this->send();
|
$this->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
session.php
12
session.php
@ -91,11 +91,7 @@ class Session
|
|||||||
public function csrfToken(): string
|
public function csrfToken(): string
|
||||||
{
|
{
|
||||||
$this->ensureStarted();
|
$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'];
|
return $_SESSION['_csrf_token'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +101,7 @@ class Session
|
|||||||
public function validateCsrf(string $token): bool
|
public function validateCsrf(string $token): bool
|
||||||
{
|
{
|
||||||
$this->ensureStarted();
|
$this->ensureStarted();
|
||||||
|
if (!isset($_SESSION['_csrf_token'])) return false;
|
||||||
if (!isset($_SESSION['_csrf_token'])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash_equals($_SESSION['_csrf_token'], $token);
|
return hash_equals($_SESSION['_csrf_token'], $token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
web.php
9
web.php
@ -86,13 +86,9 @@ class Web
|
|||||||
|
|
||||||
private function addGroupRoutes(Router $router, string $prefix, string $path, mixed $node, string $currentPath = ''): void
|
private function addGroupRoutes(Router $router, string $prefix, string $path, mixed $node, string $currentPath = ''): void
|
||||||
{
|
{
|
||||||
if ($path !== '') {
|
if ($path !== '') $currentPath = $currentPath ? "$currentPath/$path" : $path;
|
||||||
$currentPath = $currentPath ? "$currentPath/$path" : $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_array($node)) {
|
if (!is_array($node)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($node as $key => $value) {
|
foreach ($node as $key => $value) {
|
||||||
if (in_array($key, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])) {
|
if (in_array($key, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])) {
|
||||||
@ -154,7 +150,6 @@ class Web
|
|||||||
);
|
);
|
||||||
|
|
||||||
$chain();
|
$chain();
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log($e->getMessage());
|
error_log($e->getMessage());
|
||||||
$this->context->error(500, 'Internal Server Error');
|
$this->context->error(500, 'Internal Server Error');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user