diff --git a/src/Response.php b/src/Response.php index a13030c..b4c2672 100644 --- a/src/Response.php +++ b/src/Response.php @@ -209,13 +209,13 @@ public function hasHeader($name) * * @param string $name Case-insensitive header field name to add. * @param string|string[] $value Header value(s). - * @return Response + * @return static * @throws InvalidArgumentException for invalid header names or values. */ public function withAddedHeader($name, $value) { $response = $this->response->withAddedHeader($name, $value); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -228,13 +228,13 @@ public function withAddedHeader($name, $value) * new body stream. * * @param StreamInterface $body Body. - * @return Response + * @return static * @throws InvalidArgumentException When the body is not valid. */ public function withBody(StreamInterface $body) { $response = $this->response->withBody($body); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -249,13 +249,13 @@ public function withBody(StreamInterface $body) * * @param string $name Case-insensitive header field name. * @param string|string[] $value Header value(s). - * @return Response + * @return static * @throws InvalidArgumentException for invalid header names or values. */ public function withHeader($name, $value) { $response = $this->response->withHeader($name, $value); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -268,12 +268,12 @@ public function withHeader($name, $value) * the named header. * * @param string $name Case-insensitive header field name to remove. - * @return Response + * @return static */ public function withoutHeader($name) { $response = $this->response->withoutHeader($name); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -287,12 +287,12 @@ public function withoutHeader($name) * new protocol version. * * @param string $version HTTP protocol version - * @return Response + * @return static */ public function withProtocolVersion($version) { $response = $this->response->withProtocolVersion($version); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -312,13 +312,13 @@ public function withProtocolVersion($version) * @param string $reasonPhrase The reason phrase to use with the * provided status code; if none is provided, implementations MAY * use the defaults as suggested in the HTTP specification. - * @return Response + * @return static * @throws InvalidArgumentException For invalid status code arguments. */ public function withStatus($code, $reasonPhrase = '') { $response = $this->response->withStatus($code, $reasonPhrase); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -333,7 +333,7 @@ public function withStatus($code, $reasonPhrase = '') * @param int $status The HTTP status code. * @param int $options Json encoding options * @param int $depth Json encoding max depth - * @return Response + * @return static */ public function withJson($data, int $status = null, int $options = 0, int $depth = 512): ResponseInterface { @@ -351,7 +351,7 @@ public function withJson($data, int $status = null, int $options = 0, int $depth $response = $response->withStatus($status); } - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -364,7 +364,7 @@ public function withJson($data, int $status = null, int $options = 0, int $depth * * @param string $url The redirect destination. * @param int|null $status The redirect HTTP status code. - * @return Response + * @return static */ public function withRedirect(string $url, $status = null): ResponseInterface { @@ -375,7 +375,7 @@ public function withRedirect(string $url, $status = null): ResponseInterface } $response = $response->withStatus($status); - return new Response($response, $this->streamFactory); + return new static($response, $this->streamFactory); } /** @@ -386,9 +386,9 @@ public function withRedirect(string $url, $status = null): ResponseInterface * Proxies to the underlying stream and writes the provided data to it. * * @param string $data - * @return self + * @return static */ - public function write($data) + public function write($data): ResponseInterface { $this->response->getBody()->write($data); return $this; diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 3f0828f..2193111 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -423,13 +423,13 @@ public function hasHeader($name) * * @param string $name Case-insensitive header field name to add. * @param string|string[] $value Header value(s). - * @return ServerRequest + * @return static * @throws InvalidArgumentException for invalid header names or values. */ public function withAddedHeader($name, $value) { $serverRequest = $this->serverRequest->withAddedHeader($name, $value); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -445,12 +445,12 @@ public function withAddedHeader($name, $value) * @see getAttributes() * @param string $name The attribute name. * @param mixed $value The value of the attribute. - * @return ServerRequest + * @return static */ public function withAttribute($name, $value) { $serverRequest = $this->serverRequest->withAttribute($name, $value); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -466,7 +466,7 @@ public function withAttribute($name, $value) * updated attributes. * * @param array $attributes New attributes - * @return ServerRequest + * @return static */ public function withAttributes(array $attributes) { @@ -476,7 +476,7 @@ public function withAttributes(array $attributes) $serverRequest = $serverRequest->withAttribute($attribute, $value); } - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -491,12 +491,12 @@ public function withAttributes(array $attributes) * * @see getAttributes() * @param string $name The attribute name. - * @return ServerRequest + * @return static */ public function withoutAttribute($name) { $serverRequest = $this->serverRequest->withoutAttribute($name); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -509,13 +509,13 @@ public function withoutAttribute($name) * new body stream. * * @param StreamInterface $body Body. - * @return ServerRequest + * @return static * @throws InvalidArgumentException When the body is not valid. */ public function withBody(StreamInterface $body) { $serverRequest = $this->serverRequest->withBody($body); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -533,12 +533,12 @@ public function withBody(StreamInterface $body) * updated cookie values. * * @param array $cookies Array of key/value pairs representing cookies. - * @return ServerRequest + * @return static */ public function withCookieParams(array $cookies) { $serverRequest = $this->serverRequest->withCookieParams($cookies); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -553,13 +553,13 @@ public function withCookieParams(array $cookies) * * @param string $name Case-insensitive header field name. * @param string|string[] $value Header value(s). - * @return ServerRequest + * @return static * @throws InvalidArgumentException for invalid header names or values. */ public function withHeader($name, $value) { $serverRequest = $this->serverRequest->withHeader($name, $value); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -572,12 +572,12 @@ public function withHeader($name, $value) * the named header. * * @param string $name Case-insensitive header field name to remove. - * @return ServerRequest + * @return static */ public function withoutHeader($name) { $serverRequest = $this->serverRequest->withoutHeader($name); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -592,13 +592,13 @@ public function withoutHeader($name) * changed request method. * * @param string $method Case-sensitive method. - * @return ServerRequest + * @return static * @throws InvalidArgumentException for invalid HTTP methods. */ public function withMethod($method) { $serverRequest = $this->serverRequest->withMethod($method); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -625,14 +625,14 @@ public function withMethod($method) * * @param null|array|object $data The deserialized body data. This will * typically be in an array or object. - * @return ServerRequest + * @return static * @throws InvalidArgumentException if an unsupported argument type is * provided. */ public function withParsedBody($data) { $serverRequest = $this->serverRequest->withParsedBody($data); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -646,12 +646,12 @@ public function withParsedBody($data) * new protocol version. * * @param string $version HTTP protocol version - * @return ServerRequest + * @return static */ public function withProtocolVersion($version) { $serverRequest = $this->serverRequest->withProtocolVersion($version); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -674,12 +674,12 @@ public function withProtocolVersion($version) * * @param array $query Array of query string arguments, typically from * $_GET. - * @return ServerRequest + * @return static */ public function withQueryParams(array $query) { $serverRequest = $this->serverRequest->withQueryParams($query); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -697,12 +697,12 @@ public function withQueryParams(array $query) * @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various * request-target forms allowed in request messages) * @param mixed $requestTarget - * @return ServerRequest + * @return static */ public function withRequestTarget($requestTarget) { $serverRequest = $this->serverRequest->withRequestTarget($requestTarget); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -713,13 +713,13 @@ public function withRequestTarget($requestTarget) * updated body parameters. * * @param array $uploadedFiles An array tree of UploadedFileInterface instances. - * @return ServerRequest + * @return static * @throws InvalidArgumentException if an invalid structure is provided. */ public function withUploadedFiles(array $uploadedFiles) { $serverRequest = $this->serverRequest->withUploadedFiles($uploadedFiles); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -750,12 +750,12 @@ public function withUploadedFiles(array $uploadedFiles) * @link http://tools.ietf.org/html/rfc3986#section-4.3 * @param UriInterface $uri New request URI to use. * @param bool $preserveHost Preserve the original state of the Host header. - * @return ServerRequest + * @return static */ public function withUri(UriInterface $uri, $preserveHost = false) { $serverRequest = $this->serverRequest->withUri($uri, $preserveHost); - return new ServerRequest($serverRequest); + return new static($serverRequest); } /** @@ -986,9 +986,9 @@ public function getServerParam($key, $default = null) * * @param string $mediaType A HTTP media type (excluding content-type params). * @param callable $callable A callable that returns parsed contents for media type. - * @return self + * @return static */ - public function registerMediaTypeParser($mediaType, callable $callable) + public function registerMediaTypeParser($mediaType, callable $callable): ServerRequestInterface { if ($callable instanceof Closure) { $callable = $callable->bindTo($this); diff --git a/src/Uri.php b/src/Uri.php index 761967a..c32ccb5 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -226,12 +226,12 @@ public function getUserInfo() * An empty fragment value is equivalent to removing the fragment. * * @param string $fragment The fragment to use with the new instance. - * @return Uri A new instance with the specified fragment. + * @return static A new instance with the specified fragment. */ public function withFragment($fragment) { $uri = $this->uri->withFragment($fragment); - return new Uri($uri); + return new static($uri); } /** @@ -243,13 +243,13 @@ public function withFragment($fragment) * An empty host value is equivalent to removing the host. * * @param string $host The hostname to use with the new instance. - * @return Uri A new instance with the specified host. + * @return static A new instance with the specified host. * @throws InvalidArgumentException for invalid hostnames. */ public function withHost($host) { $uri = $this->uri->withHost($host); - return new Uri($uri); + return new static($uri); } /** @@ -271,13 +271,13 @@ public function withHost($host) * Implementations ensure the correct encoding as outlined in getPath(). * * @param string $path The path to use with the new instance. - * @return Uri A new instance with the specified path. + * @return static A new instance with the specified path. * @throws InvalidArgumentException for invalid paths. */ public function withPath($path) { $uri = $this->uri->withPath($path); - return new Uri($uri); + return new static($uri); } /** @@ -294,13 +294,13 @@ public function withPath($path) * * @param null|int $port The port to use with the new instance; a null value * removes the port information. - * @return Uri A new instance with the specified port. + * @return static A new instance with the specified port. * @throws InvalidArgumentException for invalid ports. */ public function withPort($port) { $uri = $this->uri->withPort($port); - return new Uri($uri); + return new static($uri); } /** @@ -315,13 +315,13 @@ public function withPort($port) * An empty query string value is equivalent to removing the query string. * * @param string $query The query string to use with the new instance. - * @return Uri A new instance with the specified query string. + * @return static A new instance with the specified query string. * @throws InvalidArgumentException for invalid query strings. */ public function withQuery($query) { $uri = $this->uri->withQuery($query); - return new Uri($uri); + return new static($uri); } /** @@ -336,13 +336,13 @@ public function withQuery($query) * An empty scheme is equivalent to removing the scheme. * * @param string $scheme The scheme to use with the new instance. - * @return Uri A new instance with the specified scheme. + * @return static A new instance with the specified scheme. * @throws InvalidArgumentException for invalid or unsupported schemes. */ public function withScheme($scheme) { $uri = $this->uri->withScheme($scheme); - return new Uri($uri); + return new static($uri); } /** @@ -357,12 +357,12 @@ public function withScheme($scheme) * * @param string $user The user name to use for authority. * @param null|string $password The password associated with $user. - * @return Uri A new instance with the specified user information. + * @return static A new instance with the specified user information. */ public function withUserInfo($user, $password = null) { $uri = $this->uri->withUserInfo($user, $password); - return new Uri($uri); + return new static($uri); } /**