swoole-framwork/core/http/Request.php

100 lines
2.4 KiB
PHP
Raw Normal View History

2024-05-20 11:51:07 +08:00
<?php
namespace Core\http;
class Request
{
protected $server = [];
protected $uri;
protected $queryParams;
protected $postParams;
protected $method;
protected $header = [];
protected $body;
protected $swooleRequest;
public function __construct(array $server, $uri, $queryParams, $postParams, $method, array $header, $body)
{
$this->server = $server;
$this->uri = $uri;
$this->queryParams = $queryParams;
$this->postParams = $postParams;
$this->method = $method;
$this->body = $body;
$this->header = $header;
}
public function getServer() :array {
return $this->server;
}
public function setServer(array $server): void {
$this->server = $server;
}
public function getUri (): string {
return $this->uri;
}
public function setUri($uri):void {
$this->uri = $uri;
}
public function getQueryParams() {
return $this->queryParams;
}
public function setQueryParams($queryParams): void
{
$this->queryParams = $queryParams;
}
public function getPostParams()
{
return $this->postParams;
}
public function setPostParams($postParams): void
{
$this->postParams = $postParams;
}
public function getMethod () {
return $this->method;
}
public function setMethod ($method):void {
$this->method = $method;
}
public function getHeader () {
return $this->header;
}
public function setHeader ($header): void {
$this->header = $header;
}
public function getBody () {
return $this->body;
}
public function setBody ($body):void {
$this->body = $body;
}
public function getSwooleRequest () {
return $this->swooleRequest;
}
public function setSwooleRequesty ($swooleRequest):void {
$this->swooleRequest = $swooleRequest;
}
public static function init (\Swoole\Http\Request $swooleRequest) {
$server = $swooleRequest->server;
$method = $server['request_method'] ?? 'GET';
$uri = $server['request_uri'];
$body = $swooleRequest->rawContent();
$request = new self($server,$uri,$swooleRequest->get,$swooleRequest->post,$method,$swooleRequest->header,$body);
$request->swooleRequest = $swooleRequest;
return $request;
}
}