This commit is contained in:
2023-04-15 23:31:16 +08:00
parent 2d9ac93a7a
commit 41a53200b3
69 changed files with 1678 additions and 749 deletions
+45 -1
View File
@@ -3,6 +3,9 @@
namespace Kiri\Router;
use Kiri\Di\Context;
use Kiri\Message\Stream;
use Kiri\Router\Base\ExceptionHandlerDispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
@@ -11,10 +14,19 @@ use Psr\Http\Message\UriInterface;
/**
* @property-read bool $isPost
*/
class Request implements ServerRequestInterface
class ServerRequest implements ServerRequestInterface
{
public array $middlewares = [];
/**
* @var string
*/
public string $exception = ExceptionHandlerDispatcher::class;
/**
* @param string $method
* @param mixed ...$params
@@ -175,6 +187,38 @@ class Request implements ServerRequestInterface
return $this->__call__(__FUNCTION__, $name, $value);
}
/**
* @param string $data
* @return ServerRequestInterface
*/
public function withHeaders(string $data): ServerRequestInterface
{
$headers = explode("\r\n\r\n", $data);
$headers = explode("\r\n", $headers[0]);
foreach ($headers as $header) {
$keyValue = explode(': ', $header);
if (!isset($keyValue[1])) {
$keyValue[1] = '';
}
$keyValue[1] = explode(', ', $keyValue[1]);
$this->withHeader(...$keyValue);
}
return $this;
}
/**
* @param string $name
* @param string|null $default
* @return string|null
*/
public function header(string $name, ?string $default = null): ?string
{
return $this->__call__(__FUNCTION__, $name, $default);
}
/**
* Return an instance with the specified header appended with the given value.
*