Skip to content

Commit 83ff8a0

Browse files
authored
Merge pull request #78 from blubolt/late-static-binding
Make use of late static binding to allow decorator extension
2 parents ff98230 + 7586b67 commit 83ff8a0

3 files changed

Lines changed: 64 additions & 64 deletions

File tree

src/Response.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ public function hasHeader($name)
209209
*
210210
* @param string $name Case-insensitive header field name to add.
211211
* @param string|string[] $value Header value(s).
212-
* @return Response
212+
* @return static
213213
* @throws InvalidArgumentException for invalid header names or values.
214214
*/
215215
public function withAddedHeader($name, $value)
216216
{
217217
$response = $this->response->withAddedHeader($name, $value);
218-
return new Response($response, $this->streamFactory);
218+
return new static($response, $this->streamFactory);
219219
}
220220

221221
/**
@@ -228,13 +228,13 @@ public function withAddedHeader($name, $value)
228228
* new body stream.
229229
*
230230
* @param StreamInterface $body Body.
231-
* @return Response
231+
* @return static
232232
* @throws InvalidArgumentException When the body is not valid.
233233
*/
234234
public function withBody(StreamInterface $body)
235235
{
236236
$response = $this->response->withBody($body);
237-
return new Response($response, $this->streamFactory);
237+
return new static($response, $this->streamFactory);
238238
}
239239

240240
/**
@@ -249,13 +249,13 @@ public function withBody(StreamInterface $body)
249249
*
250250
* @param string $name Case-insensitive header field name.
251251
* @param string|string[] $value Header value(s).
252-
* @return Response
252+
* @return static
253253
* @throws InvalidArgumentException for invalid header names or values.
254254
*/
255255
public function withHeader($name, $value)
256256
{
257257
$response = $this->response->withHeader($name, $value);
258-
return new Response($response, $this->streamFactory);
258+
return new static($response, $this->streamFactory);
259259
}
260260

261261
/**
@@ -268,12 +268,12 @@ public function withHeader($name, $value)
268268
* the named header.
269269
*
270270
* @param string $name Case-insensitive header field name to remove.
271-
* @return Response
271+
* @return static
272272
*/
273273
public function withoutHeader($name)
274274
{
275275
$response = $this->response->withoutHeader($name);
276-
return new Response($response, $this->streamFactory);
276+
return new static($response, $this->streamFactory);
277277
}
278278

279279
/**
@@ -287,12 +287,12 @@ public function withoutHeader($name)
287287
* new protocol version.
288288
*
289289
* @param string $version HTTP protocol version
290-
* @return Response
290+
* @return static
291291
*/
292292
public function withProtocolVersion($version)
293293
{
294294
$response = $this->response->withProtocolVersion($version);
295-
return new Response($response, $this->streamFactory);
295+
return new static($response, $this->streamFactory);
296296
}
297297

298298
/**
@@ -312,13 +312,13 @@ public function withProtocolVersion($version)
312312
* @param string $reasonPhrase The reason phrase to use with the
313313
* provided status code; if none is provided, implementations MAY
314314
* use the defaults as suggested in the HTTP specification.
315-
* @return Response
315+
* @return static
316316
* @throws InvalidArgumentException For invalid status code arguments.
317317
*/
318318
public function withStatus($code, $reasonPhrase = '')
319319
{
320320
$response = $this->response->withStatus($code, $reasonPhrase);
321-
return new Response($response, $this->streamFactory);
321+
return new static($response, $this->streamFactory);
322322
}
323323

324324
/**
@@ -333,7 +333,7 @@ public function withStatus($code, $reasonPhrase = '')
333333
* @param int $status The HTTP status code.
334334
* @param int $options Json encoding options
335335
* @param int $depth Json encoding max depth
336-
* @return Response
336+
* @return static
337337
*/
338338
public function withJson($data, int $status = null, int $options = 0, int $depth = 512): ResponseInterface
339339
{
@@ -351,7 +351,7 @@ public function withJson($data, int $status = null, int $options = 0, int $depth
351351
$response = $response->withStatus($status);
352352
}
353353

354-
return new Response($response, $this->streamFactory);
354+
return new static($response, $this->streamFactory);
355355
}
356356

357357
/**
@@ -364,7 +364,7 @@ public function withJson($data, int $status = null, int $options = 0, int $depth
364364
*
365365
* @param string $url The redirect destination.
366366
* @param int|null $status The redirect HTTP status code.
367-
* @return Response
367+
* @return static
368368
*/
369369
public function withRedirect(string $url, $status = null): ResponseInterface
370370
{
@@ -375,7 +375,7 @@ public function withRedirect(string $url, $status = null): ResponseInterface
375375
}
376376
$response = $response->withStatus($status);
377377

378-
return new Response($response, $this->streamFactory);
378+
return new static($response, $this->streamFactory);
379379
}
380380

381381
/**
@@ -386,9 +386,9 @@ public function withRedirect(string $url, $status = null): ResponseInterface
386386
* Proxies to the underlying stream and writes the provided data to it.
387387
*
388388
* @param string $data
389-
* @return self
389+
* @return static
390390
*/
391-
public function write($data)
391+
public function write($data): ResponseInterface
392392
{
393393
$this->response->getBody()->write($data);
394394
return $this;

src/ServerRequest.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,13 @@ public function hasHeader($name)
423423
*
424424
* @param string $name Case-insensitive header field name to add.
425425
* @param string|string[] $value Header value(s).
426-
* @return ServerRequest
426+
* @return static
427427
* @throws InvalidArgumentException for invalid header names or values.
428428
*/
429429
public function withAddedHeader($name, $value)
430430
{
431431
$serverRequest = $this->serverRequest->withAddedHeader($name, $value);
432-
return new ServerRequest($serverRequest);
432+
return new static($serverRequest);
433433
}
434434

435435
/**
@@ -445,12 +445,12 @@ public function withAddedHeader($name, $value)
445445
* @see getAttributes()
446446
* @param string $name The attribute name.
447447
* @param mixed $value The value of the attribute.
448-
* @return ServerRequest
448+
* @return static
449449
*/
450450
public function withAttribute($name, $value)
451451
{
452452
$serverRequest = $this->serverRequest->withAttribute($name, $value);
453-
return new ServerRequest($serverRequest);
453+
return new static($serverRequest);
454454
}
455455

456456
/**
@@ -466,7 +466,7 @@ public function withAttribute($name, $value)
466466
* updated attributes.
467467
*
468468
* @param array $attributes New attributes
469-
* @return ServerRequest
469+
* @return static
470470
*/
471471
public function withAttributes(array $attributes)
472472
{
@@ -476,7 +476,7 @@ public function withAttributes(array $attributes)
476476
$serverRequest = $serverRequest->withAttribute($attribute, $value);
477477
}
478478

479-
return new ServerRequest($serverRequest);
479+
return new static($serverRequest);
480480
}
481481

482482
/**
@@ -491,12 +491,12 @@ public function withAttributes(array $attributes)
491491
*
492492
* @see getAttributes()
493493
* @param string $name The attribute name.
494-
* @return ServerRequest
494+
* @return static
495495
*/
496496
public function withoutAttribute($name)
497497
{
498498
$serverRequest = $this->serverRequest->withoutAttribute($name);
499-
return new ServerRequest($serverRequest);
499+
return new static($serverRequest);
500500
}
501501

502502
/**
@@ -509,13 +509,13 @@ public function withoutAttribute($name)
509509
* new body stream.
510510
*
511511
* @param StreamInterface $body Body.
512-
* @return ServerRequest
512+
* @return static
513513
* @throws InvalidArgumentException When the body is not valid.
514514
*/
515515
public function withBody(StreamInterface $body)
516516
{
517517
$serverRequest = $this->serverRequest->withBody($body);
518-
return new ServerRequest($serverRequest);
518+
return new static($serverRequest);
519519
}
520520

521521
/**
@@ -533,12 +533,12 @@ public function withBody(StreamInterface $body)
533533
* updated cookie values.
534534
*
535535
* @param array $cookies Array of key/value pairs representing cookies.
536-
* @return ServerRequest
536+
* @return static
537537
*/
538538
public function withCookieParams(array $cookies)
539539
{
540540
$serverRequest = $this->serverRequest->withCookieParams($cookies);
541-
return new ServerRequest($serverRequest);
541+
return new static($serverRequest);
542542
}
543543

544544
/**
@@ -553,13 +553,13 @@ public function withCookieParams(array $cookies)
553553
*
554554
* @param string $name Case-insensitive header field name.
555555
* @param string|string[] $value Header value(s).
556-
* @return ServerRequest
556+
* @return static
557557
* @throws InvalidArgumentException for invalid header names or values.
558558
*/
559559
public function withHeader($name, $value)
560560
{
561561
$serverRequest = $this->serverRequest->withHeader($name, $value);
562-
return new ServerRequest($serverRequest);
562+
return new static($serverRequest);
563563
}
564564

565565
/**
@@ -572,12 +572,12 @@ public function withHeader($name, $value)
572572
* the named header.
573573
*
574574
* @param string $name Case-insensitive header field name to remove.
575-
* @return ServerRequest
575+
* @return static
576576
*/
577577
public function withoutHeader($name)
578578
{
579579
$serverRequest = $this->serverRequest->withoutHeader($name);
580-
return new ServerRequest($serverRequest);
580+
return new static($serverRequest);
581581
}
582582

583583
/**
@@ -592,13 +592,13 @@ public function withoutHeader($name)
592592
* changed request method.
593593
*
594594
* @param string $method Case-sensitive method.
595-
* @return ServerRequest
595+
* @return static
596596
* @throws InvalidArgumentException for invalid HTTP methods.
597597
*/
598598
public function withMethod($method)
599599
{
600600
$serverRequest = $this->serverRequest->withMethod($method);
601-
return new ServerRequest($serverRequest);
601+
return new static($serverRequest);
602602
}
603603

604604
/**
@@ -625,14 +625,14 @@ public function withMethod($method)
625625
*
626626
* @param null|array|object $data The deserialized body data. This will
627627
* typically be in an array or object.
628-
* @return ServerRequest
628+
* @return static
629629
* @throws InvalidArgumentException if an unsupported argument type is
630630
* provided.
631631
*/
632632
public function withParsedBody($data)
633633
{
634634
$serverRequest = $this->serverRequest->withParsedBody($data);
635-
return new ServerRequest($serverRequest);
635+
return new static($serverRequest);
636636
}
637637

638638
/**
@@ -646,12 +646,12 @@ public function withParsedBody($data)
646646
* new protocol version.
647647
*
648648
* @param string $version HTTP protocol version
649-
* @return ServerRequest
649+
* @return static
650650
*/
651651
public function withProtocolVersion($version)
652652
{
653653
$serverRequest = $this->serverRequest->withProtocolVersion($version);
654-
return new ServerRequest($serverRequest);
654+
return new static($serverRequest);
655655
}
656656

657657
/**
@@ -674,12 +674,12 @@ public function withProtocolVersion($version)
674674
*
675675
* @param array $query Array of query string arguments, typically from
676676
* $_GET.
677-
* @return ServerRequest
677+
* @return static
678678
*/
679679
public function withQueryParams(array $query)
680680
{
681681
$serverRequest = $this->serverRequest->withQueryParams($query);
682-
return new ServerRequest($serverRequest);
682+
return new static($serverRequest);
683683
}
684684

685685
/**
@@ -697,12 +697,12 @@ public function withQueryParams(array $query)
697697
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
698698
* request-target forms allowed in request messages)
699699
* @param mixed $requestTarget
700-
* @return ServerRequest
700+
* @return static
701701
*/
702702
public function withRequestTarget($requestTarget)
703703
{
704704
$serverRequest = $this->serverRequest->withRequestTarget($requestTarget);
705-
return new ServerRequest($serverRequest);
705+
return new static($serverRequest);
706706
}
707707

708708
/**
@@ -713,13 +713,13 @@ public function withRequestTarget($requestTarget)
713713
* updated body parameters.
714714
*
715715
* @param array $uploadedFiles An array tree of UploadedFileInterface instances.
716-
* @return ServerRequest
716+
* @return static
717717
* @throws InvalidArgumentException if an invalid structure is provided.
718718
*/
719719
public function withUploadedFiles(array $uploadedFiles)
720720
{
721721
$serverRequest = $this->serverRequest->withUploadedFiles($uploadedFiles);
722-
return new ServerRequest($serverRequest);
722+
return new static($serverRequest);
723723
}
724724

725725
/**
@@ -750,12 +750,12 @@ public function withUploadedFiles(array $uploadedFiles)
750750
* @link http://tools.ietf.org/html/rfc3986#section-4.3
751751
* @param UriInterface $uri New request URI to use.
752752
* @param bool $preserveHost Preserve the original state of the Host header.
753-
* @return ServerRequest
753+
* @return static
754754
*/
755755
public function withUri(UriInterface $uri, $preserveHost = false)
756756
{
757757
$serverRequest = $this->serverRequest->withUri($uri, $preserveHost);
758-
return new ServerRequest($serverRequest);
758+
return new static($serverRequest);
759759
}
760760

761761
/**
@@ -986,9 +986,9 @@ public function getServerParam($key, $default = null)
986986
*
987987
* @param string $mediaType A HTTP media type (excluding content-type params).
988988
* @param callable $callable A callable that returns parsed contents for media type.
989-
* @return self
989+
* @return static
990990
*/
991-
public function registerMediaTypeParser($mediaType, callable $callable)
991+
public function registerMediaTypeParser($mediaType, callable $callable): ServerRequestInterface
992992
{
993993
if ($callable instanceof Closure) {
994994
$callable = $callable->bindTo($this);

0 commit comments

Comments
 (0)