Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Fixed php8 warnings
  • Loading branch information
Jobians authored Jul 21, 2024
1 parent 89c3b80 commit 68d0f5b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
9 changes: 7 additions & 2 deletions core/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ public function __get($name)
return $_GET;
case 'post':
return $_POST;
case 'header':
case 'body':
$requestBody = file_get_contents('php://input');
return json_decode($requestBody, true, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
case 'headers':
return $this->getHeaders();
case 'cookies':
return $_COOKIE;
case 'route':
return $_SERVER['REQUEST_URI'];
case 'session':
session_start();
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
return $_SESSION;
case 'method':
return $_SERVER['REQUEST_METHOD'];
Expand Down
24 changes: 19 additions & 5 deletions core/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@ class Response
public function send($content, $http_headers = []) {
if (is_array($http_headers) && !empty($http_headers)) {
foreach ($http_headers as $key => $value) {
header($key . ': ' . $value);
if (!headers_sent()) {
header($key . ': ' . $value);
}
}
}
echo $content;
}

public function json($data)
{
header('Content-Type: application/json');
if (!headers_sent()) {
header('Content-Type: application/json');
}
echo json_encode($data);
}

public function redirect($url)
{
header("Location: $url");
ob_start();
if (!headers_sent()) {
header("Location: $url");
}
ob_end_flush();
exit();
}

Expand Down Expand Up @@ -112,18 +120,24 @@ public function render($template, $data=[])
}

public function setHeader($name, $value) {
header($name.':'.$value);
if (!headers_sent()) {
header($name.':'.$value);
}
}

public function setSession($name, $value)
{
session_start();
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$_SESSION[$name] = $value;
}

public function setCookie($name, $value, $expires = 0, $path = '', $domain = '', $secure = false, $httponly = false)
{
ob_start();
setcookie($name, $value, $expires, $path, $domain, $secure, $httponly);
ob_end_flush();
}

public function status($statusCode)
Expand Down
2 changes: 2 additions & 0 deletions core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ private function processHandlers($req, $res, $handlers)
}

protected function matchRoute($route, $path, $req) {
$path = $path ?? "";
$route = $route ?? "";
$routeParts = explode('/', trim($route, '/'));
$pathParts = explode('/', trim($path, '/'));

Expand Down

0 comments on commit 68d0f5b

Please sign in to comment.