Skip to content

Commit 68d0f5b

Browse files
authored
Add files via upload
Fixed php8 warnings
1 parent 89c3b80 commit 68d0f5b

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

core/Request.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,19 @@ public function __get($name)
9191
return $_GET;
9292
case 'post':
9393
return $_POST;
94-
case 'header':
94+
case 'body':
95+
$requestBody = file_get_contents('php://input');
96+
return json_decode($requestBody, true, 512, JSON_PARTIAL_OUTPUT_ON_ERROR);
97+
case 'headers':
9598
return $this->getHeaders();
9699
case 'cookies':
97100
return $_COOKIE;
98101
case 'route':
99102
return $_SERVER['REQUEST_URI'];
100103
case 'session':
101-
session_start();
104+
if (session_status() === PHP_SESSION_NONE) {
105+
session_start();
106+
}
102107
return $_SESSION;
103108
case 'method':
104109
return $_SERVER['REQUEST_METHOD'];

core/Response.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@ class Response
1616
public function send($content, $http_headers = []) {
1717
if (is_array($http_headers) && !empty($http_headers)) {
1818
foreach ($http_headers as $key => $value) {
19-
header($key . ': ' . $value);
19+
if (!headers_sent()) {
20+
header($key . ': ' . $value);
21+
}
2022
}
2123
}
2224
echo $content;
2325
}
2426

2527
public function json($data)
2628
{
27-
header('Content-Type: application/json');
29+
if (!headers_sent()) {
30+
header('Content-Type: application/json');
31+
}
2832
echo json_encode($data);
2933
}
3034

3135
public function redirect($url)
3236
{
33-
header("Location: $url");
37+
ob_start();
38+
if (!headers_sent()) {
39+
header("Location: $url");
40+
}
41+
ob_end_flush();
3442
exit();
3543
}
3644

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

114122
public function setHeader($name, $value) {
115-
header($name.':'.$value);
123+
if (!headers_sent()) {
124+
header($name.':'.$value);
125+
}
116126
}
117127

118128
public function setSession($name, $value)
119129
{
120-
session_start();
130+
if (session_status() === PHP_SESSION_NONE) {
131+
session_start();
132+
}
121133
$_SESSION[$name] = $value;
122134
}
123135

124136
public function setCookie($name, $value, $expires = 0, $path = '', $domain = '', $secure = false, $httponly = false)
125137
{
138+
ob_start();
126139
setcookie($name, $value, $expires, $path, $domain, $secure, $httponly);
140+
ob_end_flush();
127141
}
128142

129143
public function status($statusCode)

core/Router.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ private function processHandlers($req, $res, $handlers)
146146
}
147147

148148
protected function matchRoute($route, $path, $req) {
149+
$path = $path ?? "";
150+
$route = $route ?? "";
149151
$routeParts = explode('/', trim($route, '/'));
150152
$pathParts = explode('/', trim($path, '/'));
151153

0 commit comments

Comments
 (0)