diff --git a/system/src/Grav/Framework/Form/Traits/FormTrait.php b/system/src/Grav/Framework/Form/Traits/FormTrait.php index 4ba99add0..f29fe9a78 100644 --- a/system/src/Grav/Framework/Form/Traits/FormTrait.php +++ b/system/src/Grav/Framework/Form/Traits/FormTrait.php @@ -476,7 +476,7 @@ trait FormTrait } /** - * @return string + * @return array */ protected function doSerialize(): array { diff --git a/system/src/Grav/Framework/Psr7/Response.php b/system/src/Grav/Framework/Psr7/Response.php index c8ba17a23..960621dbf 100644 --- a/system/src/Grav/Framework/Psr7/Response.php +++ b/system/src/Grav/Framework/Psr7/Response.php @@ -63,7 +63,7 @@ class Response implements ResponseInterface throw new RuntimeException(json_last_error_msg(), json_last_error()); } - $response = $this->message + $response = $this->getResponse() ->withHeader('Content-Type', 'application/json;charset=utf-8') ->withBody(new Stream($json)); @@ -91,7 +91,7 @@ class Response implements ResponseInterface */ public function withRedirect(string $url, $status = null): ResponseInterface { - $response = $this->message->withHeader('Location', $url); + $response = $this->getResponse()->withHeader('Location', $url); if ($status === null) { $status = 302; @@ -112,7 +112,7 @@ class Response implements ResponseInterface */ public function isEmpty(): bool { - return \in_array($this->message->getStatusCode(), [204, 205, 304], true); + return \in_array($this->getResponse()->getStatusCode(), [204, 205, 304], true); } @@ -125,7 +125,7 @@ class Response implements ResponseInterface */ public function isOk(): bool { - return $this->message->getStatusCode() === 200; + return $this->getResponse()->getStatusCode() === 200; } /** @@ -137,7 +137,7 @@ class Response implements ResponseInterface */ public function isRedirect(): bool { - return \in_array($this->message->getStatusCode(), [301, 302, 303, 307, 308], true); + return \in_array($this->getResponse()->getStatusCode(), [301, 302, 303, 307, 308], true); } /** @@ -150,7 +150,7 @@ class Response implements ResponseInterface */ public function isForbidden(): bool { - return $this->message->getStatusCode() === 403; + return $this->getResponse()->getStatusCode() === 403; } /** @@ -162,7 +162,7 @@ class Response implements ResponseInterface */ public function isNotFound(): bool { - return $this->message->getStatusCode() === 404; + return $this->getResponse()->getStatusCode() === 404; } /** @@ -174,7 +174,9 @@ class Response implements ResponseInterface */ public function isInformational(): bool { - return $this->message->getStatusCode() >= 100 && $this->message->getStatusCode() < 200; + $response = $this->getResponse(); + + return $response->getStatusCode() >= 100 && $response->getStatusCode() < 200; } /** @@ -186,7 +188,9 @@ class Response implements ResponseInterface */ public function isSuccessful(): bool { - return $this->message->getStatusCode() >= 200 && $this->message->getStatusCode() < 300; + $response = $this->getResponse(); + + return $response->getStatusCode() >= 200 && $response->getStatusCode() < 300; } /** @@ -198,7 +202,9 @@ class Response implements ResponseInterface */ public function isRedirection(): bool { - return $this->message->getStatusCode() >= 300 && $this->message->getStatusCode() < 400; + $response = $this->getResponse(); + + return $response->getStatusCode() >= 300 && $response->getStatusCode() < 400; } /** @@ -210,7 +216,9 @@ class Response implements ResponseInterface */ public function isClientError(): bool { - return $this->message->getStatusCode() >= 400 && $this->message->getStatusCode() < 500; + $response = $this->getResponse(); + + return $response->getStatusCode() >= 400 && $response->getStatusCode() < 500; } /** @@ -222,7 +230,9 @@ class Response implements ResponseInterface */ public function isServerError(): bool { - return $this->message->getStatusCode() >= 500 && $this->message->getStatusCode() < 600; + $response = $this->getResponse(); + + return $response->getStatusCode() >= 500 && $response->getStatusCode() < 600; } /** @@ -234,20 +244,21 @@ class Response implements ResponseInterface */ public function __toString(): string { + $response = $this->getResponse(); $output = sprintf( 'HTTP/%s %s %s%s', - $this->message->getProtocolVersion(), - $this->message->getStatusCode(), - $this->message->getReasonPhrase(), + $response->getProtocolVersion(), + $response->getStatusCode(), + $response->getReasonPhrase(), self::EOL ); - foreach ($this->message->getHeaders() as $name => $values) { - $output .= sprintf('%s: %s', $name, $this->message->getHeaderLine($name)) . self::EOL; + foreach ($response->getHeaders() as $name => $values) { + $output .= sprintf('%s: %s', $name, $response->getHeaderLine($name)) . self::EOL; } $output .= self::EOL; - $output .= (string) $this->message->getBody(); + $output .= (string) $response->getBody(); return $output; } diff --git a/system/src/Grav/Framework/Psr7/ServerRequest.php b/system/src/Grav/Framework/Psr7/ServerRequest.php index dca0a2808..bb6b8b8b5 100644 --- a/system/src/Grav/Framework/Psr7/ServerRequest.php +++ b/system/src/Grav/Framework/Psr7/ServerRequest.php @@ -64,7 +64,7 @@ class ServerRequest implements ServerRequestInterface */ public function getContentType(): ?string { - $result = $this->message->getHeader('Content-Type'); + $result = $this->getRequest()->getHeader('Content-Type'); return $result ? $result[0] : null; } @@ -78,7 +78,7 @@ class ServerRequest implements ServerRequestInterface */ public function getContentLength(): ?int { - $result = $this->message->getHeader('Content-Length'); + $result = $this->getRequest()->getHeader('Content-Length'); return $result ? (int) $result[0] : null; } @@ -95,7 +95,7 @@ class ServerRequest implements ServerRequestInterface */ public function getCookieParam($key, $default = null) { - $cookies = $this->message->getCookieParams(); + $cookies = $this->getRequest()->getCookieParams(); $result = $default; if (isset($cookies[$key])) { @@ -256,7 +256,7 @@ class ServerRequest implements ServerRequestInterface */ public function getServerParam($key, $default = null) { - $serverParams = $this->message->getServerParams(); + $serverParams = $this->getRequest()->getServerParams(); return $serverParams[$key] ?? $default; } @@ -271,7 +271,7 @@ class ServerRequest implements ServerRequestInterface */ public function isMethod($method): bool { - return $this->message->getMethod() === $method; + return $this->getRequest()->getMethod() === $method; } /** @@ -367,6 +367,6 @@ class ServerRequest implements ServerRequestInterface */ public function isXhr(): bool { - return $this->message->getHeaderLine('X-Requested-With') === 'XMLHttpRequest'; + return $this->getRequest()->getHeaderLine('X-Requested-With') === 'XMLHttpRequest'; } } diff --git a/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php index 4cd21eede..ab1ffadcf 100644 --- a/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php +++ b/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php @@ -20,14 +20,29 @@ use Psr\Http\Message\UriInterface; trait RequestDecoratorTrait { use MessageDecoratorTrait { - getMessage as getRequest; + getMessage as private; + } + + /** + * Returns the decorated request. + * + * Since the underlying Request is immutable as well + * exposing it is not an issue, because it's state cannot be altered + * + * @return RequestInterface + */ + public function getRequest(): RequestInterface + { + /** @var RequestInterface $message */ + $message = $this->getMessage(); + + return $message; } /** * Exchanges the underlying request with another. * * @param RequestInterface $request - * * @return self */ public function withRequest(RequestInterface $request): self @@ -43,7 +58,7 @@ trait RequestDecoratorTrait */ public function getRequestTarget(): string { - return $this->message->getRequestTarget(); + return $this->getRequest()->getRequestTarget(); } /** @@ -52,7 +67,7 @@ trait RequestDecoratorTrait public function withRequestTarget($requestTarget): self { $new = clone $this; - $new->message = $this->message->withRequestTarget($requestTarget); + $new->message = $this->getRequest()->withRequestTarget($requestTarget); return $new; } @@ -62,7 +77,7 @@ trait RequestDecoratorTrait */ public function getMethod(): string { - return $this->message->getMethod(); + return $this->getRequest()->getMethod(); } /** @@ -71,7 +86,7 @@ trait RequestDecoratorTrait public function withMethod($method): self { $new = clone $this; - $new->message = $this->message->withMethod($method); + $new->message = $this->getRequest()->withMethod($method); return $new; } @@ -81,7 +96,7 @@ trait RequestDecoratorTrait */ public function getUri(): UriInterface { - return $this->message->getUri(); + return $this->getRequest()->getUri(); } /** @@ -90,7 +105,7 @@ trait RequestDecoratorTrait public function withUri(UriInterface $uri, $preserveHost = false): self { $new = clone $this; - $new->message = $this->message->withUri($uri, $preserveHost); + $new->message = $this->getRequest()->withUri($uri, $preserveHost); return $new; } diff --git a/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php index 44507af5e..32a1bfb9c 100644 --- a/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php +++ b/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php @@ -19,7 +19,23 @@ use Psr\Http\Message\ResponseInterface; trait ResponseDecoratorTrait { use MessageDecoratorTrait { - getMessage as getResponse; + getMessage as private; + } + + /** + * Returns the decorated response. + * + * Since the underlying Response is immutable as well + * exposing it is not an issue, because it's state cannot be altered + * + * @return ResponseInterface + */ + public function getResponse(): ResponseInterface + { + /** @var ResponseInterface $message */ + $message = $this->getMessage(); + + return $message; } /** @@ -42,7 +58,7 @@ trait ResponseDecoratorTrait */ public function getStatusCode(): int { - return $this->message->getStatusCode(); + return $this->getResponse()->getStatusCode(); } /** @@ -51,7 +67,7 @@ trait ResponseDecoratorTrait public function withStatus($code, $reasonPhrase = ''): self { $new = clone $this; - $new->message = $this->message->withStatus($code, $reasonPhrase); + $new->message = $this->getResponse()->withStatus($code, $reasonPhrase); return $new; } @@ -61,6 +77,6 @@ trait ResponseDecoratorTrait */ public function getReasonPhrase(): string { - return $this->message->getReasonPhrase(); + return $this->getResponse()->getReasonPhrase(); } } diff --git a/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php index 6543f0d6a..03541956a 100644 --- a/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php +++ b/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php @@ -11,16 +11,34 @@ declare(strict_types=1); namespace Grav\Framework\Psr7\Traits; +use Psr\Http\Message\ServerRequestInterface; + trait ServerRequestDecoratorTrait { use RequestDecoratorTrait; + /** + * Returns the decorated request. + * + * Since the underlying Request is immutable as well + * exposing it is not an issue, because it's state cannot be altered + * + * @return ServerRequestInterface + */ + public function getRequest(): ServerRequestInterface + { + /** @var ServerRequestInterface $message */ + $message = $this->getMessage(); + + return $message; + } + /** * @inheritdoc */ public function getAttribute($name, $default = null) { - return $this->message->getAttribute($name, $default); + return $this->getRequest()->getAttribute($name, $default); } /** @@ -28,7 +46,7 @@ trait ServerRequestDecoratorTrait */ public function getAttributes() { - return $this->message->getAttributes(); + return $this->getRequest()->getAttributes(); } @@ -37,7 +55,7 @@ trait ServerRequestDecoratorTrait */ public function getCookieParams() { - return $this->message->getCookieParams(); + return $this->getRequest()->getCookieParams(); } /** @@ -45,7 +63,7 @@ trait ServerRequestDecoratorTrait */ public function getParsedBody() { - return $this->message->getParsedBody(); + return $this->getRequest()->getParsedBody(); } /** @@ -53,7 +71,7 @@ trait ServerRequestDecoratorTrait */ public function getQueryParams() { - return $this->message->getQueryParams(); + return $this->getRequest()->getQueryParams(); } /** @@ -61,7 +79,7 @@ trait ServerRequestDecoratorTrait */ public function getServerParams() { - return $this->message->getServerParams(); + return $this->getRequest()->getServerParams(); } /** @@ -69,7 +87,7 @@ trait ServerRequestDecoratorTrait */ public function getUploadedFiles() { - return $this->message->getUploadedFiles(); + return $this->getRequest()->getUploadedFiles(); } /** @@ -78,7 +96,7 @@ trait ServerRequestDecoratorTrait public function withAttribute($name, $value) { $new = clone $this; - $new->message = $this->message->withAttribute($name, $value); + $new->message = $this->getRequest()->withAttribute($name, $value); return $new; } @@ -102,7 +120,7 @@ trait ServerRequestDecoratorTrait public function withoutAttribute($name) { $new = clone $this; - $new->message = $this->message->withoutAttribute($name); + $new->message = $this->getRequest()->withoutAttribute($name); return $new; } @@ -113,7 +131,7 @@ trait ServerRequestDecoratorTrait public function withCookieParams(array $cookies) { $new = clone $this; - $new->message = $this->message->withCookieParams($cookies); + $new->message = $this->getRequest()->withCookieParams($cookies); return $new; } @@ -124,7 +142,7 @@ trait ServerRequestDecoratorTrait public function withParsedBody($data) { $new = clone $this; - $new->message = $this->message->withParsedBody($data); + $new->message = $this->getRequest()->withParsedBody($data); return $new; } @@ -135,7 +153,7 @@ trait ServerRequestDecoratorTrait public function withQueryParams(array $query) { $new = clone $this; - $new->message = $this->message->withQueryParams($query); + $new->message = $this->getRequest()->withQueryParams($query); return $new; } @@ -146,7 +164,7 @@ trait ServerRequestDecoratorTrait public function withUploadedFiles(array $uploadedFiles) { $new = clone $this; - $new->message = $this->message->withUploadedFiles($uploadedFiles); + $new->message = $this->getRequest()->withUploadedFiles($uploadedFiles); return $new; } diff --git a/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php b/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php index e1e1af6bc..83097d550 100644 --- a/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php +++ b/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php @@ -65,6 +65,7 @@ trait UriDecorationTrait public function withScheme($scheme): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withScheme($scheme); @@ -73,6 +74,7 @@ trait UriDecorationTrait public function withUserInfo($user, $password = null): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withUserInfo($user, $password); @@ -81,6 +83,7 @@ trait UriDecorationTrait public function withHost($host): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withHost($host); @@ -89,6 +92,7 @@ trait UriDecorationTrait public function withPort($port): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withPort($port); @@ -97,6 +101,7 @@ trait UriDecorationTrait public function withPath($path): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withPath($path); @@ -105,6 +110,7 @@ trait UriDecorationTrait public function withQuery($query): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withQuery($query); @@ -113,6 +119,7 @@ trait UriDecorationTrait public function withFragment($fragment): UriInterface { + /** @var UriInterface $new */ $new = clone $this; $new->uri = $this->uri->withFragment($fragment); diff --git a/system/src/Grav/Framework/RequestHandler/RequestHandler.php b/system/src/Grav/Framework/RequestHandler/RequestHandler.php index ef1f83805..c4d53873b 100644 --- a/system/src/Grav/Framework/RequestHandler/RequestHandler.php +++ b/system/src/Grav/Framework/RequestHandler/RequestHandler.php @@ -37,11 +37,11 @@ class RequestHandler implements RequestHandlerInterface /** * Add callable initializing Middleware that will be executed as soon as possible. * - * @param $name + * @param string $name * @param callable $callable * @return $this */ - public function addCallable($name, callable $callable): self + public function addCallable(string $name, callable $callable): self { $this->container[$name] = $callable; array_unshift($this->middleware, $name); @@ -52,11 +52,11 @@ class RequestHandler implements RequestHandlerInterface /** * Add Middleware that will be executed as soon as possible. * - * @param $name - * @param callable $callable + * @param string $name + * @param MiddlewareInterface $middleware * @return $this */ - public function addMiddleware($name, MiddlewareInterface $middleware): self + public function addMiddleware(string $name, MiddlewareInterface $middleware): self { $this->container[$name] = $middleware; array_unshift($this->middleware, $name); diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 5a625945a..f287694c8 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -187,7 +187,7 @@ class Route /** * Allow the ability to set the route to something else * - * @param $route + * @param string $route * @return $this */ public function withRoute($route) @@ -199,7 +199,7 @@ class Route /** * Allow the ability to set the root to something else * - * @param $root + * @param string $root * @return $this */ public function withRoot($root)