This commit is contained in:
2021-09-09 16:50:52 +08:00
parent d5b65f0d89
commit 7e2431cb6d
2 changed files with 28 additions and 26 deletions
+9 -9
View File
@@ -252,31 +252,31 @@ class Response implements ResponseInterface
/** /**
* @param string $data * @param string $value
* @return ResponseInterface * @return ResponseInterface
*/ */
public function withAccessControlAllowOrigin(string $data): ResponseInterface public function withAccessControlAllowOrigin(string $value): ResponseInterface
{ {
return $this->__call__()->{__METHOD__}($data); return $this->__call__()->{__METHOD__}($value);
} }
/** /**
* @param string $data * @param string $value
* @return ResponseInterface * @return ResponseInterface
*/ */
public function withAccessControlRequestMethod(string $data): ResponseInterface public function withAccessControlRequestMethod(string $value): ResponseInterface
{ {
return $this->__call__()->{__METHOD__}($data); return $this->__call__()->{__METHOD__}($value);
} }
/** /**
* @param string $data * @param string $value
* @return ResponseInterface * @return ResponseInterface
*/ */
public function withAccessControlAllowHeaders(string $data): ResponseInterface public function withAccessControlAllowHeaders(string $value): ResponseInterface
{ {
return $this->__call__()->{__METHOD__}($data); return $this->__call__()->{__METHOD__}($value);
} }
} }
+19 -17
View File
@@ -5,6 +5,8 @@ namespace Server\Message;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri\Core\Xml; use Kiri\Core\Xml;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
use Server\RequestInterface;
use Server\ResponseInterface;
/** /**
@@ -56,9 +58,9 @@ trait Message
* @param null $httponly * @param null $httponly
* @param null $samesite * @param null $samesite
* @param null $priority * @param null $priority
* @return static * @return RequestInterface|ResponseInterface
*/ */
public function withCookie($name, $value = null, $expires = null, $path = null, $domain = null, $secure = null, $httponly = null, $samesite = null, $priority = null): static public function withCookie($name, $value = null, $expires = null, $path = null, $domain = null, $secure = null, $httponly = null, $samesite = null, $priority = null): RequestInterface|ResponseInterface
{ {
$this->cookies[$name] = [$value, $expires, $path, $domain, $secure, $httponly, $samesite, $priority]; $this->cookies[$name] = [$value, $expires, $path, $domain, $secure, $httponly, $samesite, $priority];
return $this; return $this;
@@ -103,9 +105,9 @@ trait Message
/** /**
* @param $version * @param $version
* @return $this * @return RequestInterface|ResponseInterface
*/ */
public function withProtocolVersion($version): static public function withProtocolVersion($version): RequestInterface|ResponseInterface
{ {
$this->version = $version; $this->version = $version;
return $this; return $this;
@@ -153,9 +155,9 @@ trait Message
/** /**
* @param \Swoole\Http\Request $request * @param \Swoole\Http\Request $request
* @return $this * @return RequestInterface|ResponseInterface
*/ */
private function parseRequestHeaders(\Swoole\Http\Request $request): static private function parseRequestHeaders(\Swoole\Http\Request $request): RequestInterface|ResponseInterface
{ {
$index = strpos($request->getData(), "\r\n\r\n"); $index = strpos($request->getData(), "\r\n\r\n");
$headers = explode("\r\n", substr($request->getData(), 0, $index)); $headers = explode("\r\n", substr($request->getData(), 0, $index));
@@ -194,9 +196,9 @@ trait Message
/** /**
* @param $name * @param $name
* @param $value * @param $value
* @return static * @return RequestInterface|ResponseInterface
*/ */
public function withHeader($name, $value): static public function withHeader($name, $value): RequestInterface|ResponseInterface
{ {
if (!is_array($value)) { if (!is_array($value)) {
$value = [$value]; $value = [$value];
@@ -209,10 +211,10 @@ trait Message
/** /**
* @param $name * @param $name
* @param $value * @param $value
* @return static * @return RequestInterface|ResponseInterface
* @throws * @throws
*/ */
public function withAddedHeader($name, $value): static public function withAddedHeader($name, $value): RequestInterface|ResponseInterface
{ {
if (!array_key_exists($name, $this->headers)) { if (!array_key_exists($name, $this->headers)) {
throw new \Exception('Headers `' . $name . '` not exists.'); throw new \Exception('Headers `' . $name . '` not exists.');
@@ -224,9 +226,9 @@ trait Message
/** /**
* @param $name * @param $name
* @return $this * @return RequestInterface|ResponseInterface
*/ */
public function withoutHeader($name): static public function withoutHeader($name): RequestInterface|ResponseInterface
{ {
unset($this->headers[$name]); unset($this->headers[$name]);
return $this; return $this;
@@ -236,7 +238,7 @@ trait Message
/** /**
* @return string * @return string
*/ */
public function getBody(): string #[Pure] public function getBody(): string
{ {
return $this->stream->getContents(); return $this->stream->getContents();
} }
@@ -244,9 +246,9 @@ trait Message
/** /**
* @param StreamInterface $body * @param StreamInterface $body
* @return static * @return RequestInterface|ResponseInterface
*/ */
public function withBody(StreamInterface $body): static public function withBody(StreamInterface $body): RequestInterface|ResponseInterface
{ {
$this->stream = $body; $this->stream = $body;
return $this; return $this;
@@ -283,9 +285,9 @@ trait Message
/** /**
* @param $host * @param $host
* @return \Server\Message\Request|\Server\Message\Response * @return Request|Response
*/ */
public function redirectTo($host) public function redirectTo($host): RequestInterface|ResponseInterface
{ {
return $this->withHeader('Location', $host) return $this->withHeader('Location', $host)
->withStatus(302); ->withStatus(302);