1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
|
From: =?utf-8?q?Maur=C3=ADcio_Meneghini_Fauth?= <mauricio@fauth.dev>
Date: Wed, 19 Jul 2023 16:19:49 -0300
Subject: Add support for PSR HTTP Message v2
Origin: upstream
Forwarded: https://github.com/slimphp/Slim-Psr7/pull/289
Bug-Debian: https://bugs.debian.org/1093579
Co-Authored-By: William Desportes <williamdes@wdes.fr>
---
Slim/Http/Message.php | 22 +++++++++++-----------
Slim/Http/NonBufferedBody.php | 26 +++++++++++++-------------
Slim/Http/Request.php | 37 +++++++++++++++++++------------------
Slim/Http/Response.php | 9 +++++----
Slim/Http/Stream.php | 24 ++++++++++++------------
Slim/Http/UploadedFile.php | 12 ++++++------
Slim/Http/Uri.php | 32 ++++++++++++++++----------------
composer.json | 4 ++--
8 files changed, 84 insertions(+), 82 deletions(-)
diff --git a/Slim/Http/Message.php b/Slim/Http/Message.php
index 0dc7b4d..f157741 100644
--- a/Slim/Http/Message.php
+++ b/Slim/Http/Message.php
@@ -64,7 +64,7 @@ abstract class Message implements MessageInterface
*
* @return string
*/
- public function getProtocolVersion()
+ public function getProtocolVersion(): string
{
return $this->protocolVersion;
}
@@ -85,7 +85,7 @@ abstract class Message implements MessageInterface
*
* @throws InvalidArgumentException if the http version is an invalid number
*/
- public function withProtocolVersion($version)
+ public function withProtocolVersion($version): MessageInterface
{
if (!isset(self::$validProtocolVersions[$version])) {
throw new InvalidArgumentException(
@@ -125,7 +125,7 @@ abstract class Message implements MessageInterface
*
* @return array
*/
- public function getHeaders()
+ public function getHeaders(): array
{
return $this->headers->all();
}
@@ -140,7 +140,7 @@ abstract class Message implements MessageInterface
*
* @return bool
*/
- public function hasHeader($name)
+ public function hasHeader(string $name): bool
{
return $this->headers->has($name);
}
@@ -158,7 +158,7 @@ abstract class Message implements MessageInterface
*
* @return string[]
*/
- public function getHeader($name)
+ public function getHeader(string $name): array
{
return $this->headers->get($name, []);
}
@@ -181,7 +181,7 @@ abstract class Message implements MessageInterface
*
* @return string
*/
- public function getHeaderLine($name)
+ public function getHeaderLine(string $name): string
{
return implode(',', $this->headers->get($name, []));
}
@@ -201,7 +201,7 @@ abstract class Message implements MessageInterface
*
* @return static
*/
- public function withHeader($name, $value)
+ public function withHeader($name, $value): MessageInterface
{
$clone = clone $this;
$clone->headers->set($name, $value);
@@ -225,7 +225,7 @@ abstract class Message implements MessageInterface
*
* @return static
*/
- public function withAddedHeader($name, $value)
+ public function withAddedHeader($name, $value): MessageInterface
{
$clone = clone $this;
$clone->headers->add($name, $value);
@@ -250,7 +250,7 @@ abstract class Message implements MessageInterface
*
* @return static
*/
- public function withoutHeader($name)
+ public function withoutHeader($name): MessageInterface
{
$clone = clone $this;
$clone->headers->remove($name);
@@ -267,7 +267,7 @@ abstract class Message implements MessageInterface
*
* @return StreamInterface Returns the body as a stream.
*/
- public function getBody()
+ public function getBody(): StreamInterface
{
return $this->body;
}
@@ -285,7 +285,7 @@ abstract class Message implements MessageInterface
*
* @return static
*/
- public function withBody(StreamInterface $body)
+ public function withBody(StreamInterface $body): MessageInterface
{
$clone = clone $this;
$clone->body = $body;
diff --git a/Slim/Http/NonBufferedBody.php b/Slim/Http/NonBufferedBody.php
index 352ff59..f823d54 100644
--- a/Slim/Http/NonBufferedBody.php
+++ b/Slim/Http/NonBufferedBody.php
@@ -18,7 +18,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function __toString()
+ public function __toString(): string
{
return '';
}
@@ -26,7 +26,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function close()
+ public function close(): void
{
}
@@ -41,7 +41,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function getSize()
+ public function getSize(): ?int
{
return null;
}
@@ -49,7 +49,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function tell()
+ public function tell(): int
{
return 0;
}
@@ -57,7 +57,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function eof()
+ public function eof(): bool
{
return true;
}
@@ -65,7 +65,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function isSeekable()
+ public function isSeekable(): bool
{
return false;
}
@@ -73,21 +73,21 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function seek($offset, $whence = SEEK_SET)
+ public function seek(int $offset, int $whence = SEEK_SET): void
{
}
/**
* {@inheritdoc}
*/
- public function rewind()
+ public function rewind(): void
{
}
/**
* {@inheritdoc}
*/
- public function isWritable()
+ public function isWritable(): bool
{
return true;
}
@@ -95,7 +95,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function write($string)
+ public function write(string $string): int
{
$buffered = '';
while (0 < ob_get_level()) {
@@ -112,7 +112,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function isReadable()
+ public function isReadable(): bool
{
return false;
}
@@ -120,7 +120,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function read($length)
+ public function read(int $length): string
{
return '';
}
@@ -128,7 +128,7 @@ class NonBufferedBody implements StreamInterface
/**
* {@inheritdoc}
*/
- public function getContents()
+ public function getContents(): string
{
return '';
}
diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php
index 5df7405..02425d7 100644
--- a/Slim/Http/Request.php
+++ b/Slim/Http/Request.php
@@ -9,6 +9,7 @@ namespace Slim\Http;
use Closure;
use InvalidArgumentException;
+use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
@@ -257,7 +258,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return string
*/
- public function getMethod()
+ public function getMethod(): string
{
if ($this->method === null) {
$this->method = $this->originalMethod;
@@ -309,7 +310,7 @@ class Request extends Message implements ServerRequestInterface
*
* @throws InvalidArgumentException for invalid HTTP methods.
*/
- public function withMethod($method)
+ public function withMethod(string $method): RequestInterface
{
$method = $this->filterMethod($method);
$clone = clone $this;
@@ -475,7 +476,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return string
*/
- public function getRequestTarget()
+ public function getRequestTarget(): string
{
if ($this->requestTarget) {
return $this->requestTarget;
@@ -523,7 +524,7 @@ class Request extends Message implements ServerRequestInterface
*
* @throws InvalidArgumentException if the request target is invalid
*/
- public function withRequestTarget($requestTarget)
+ public function withRequestTarget(string $requestTarget): RequestInterface
{
if (preg_match('#\s#', $requestTarget)) {
throw new InvalidArgumentException(
@@ -545,7 +546,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return UriInterface
*/
- public function getUri()
+ public function getUri(): UriInterface
{
return $this->uri;
}
@@ -582,7 +583,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return static
*/
- public function withUri(UriInterface $uri, $preserveHost = false)
+ public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
{
$clone = clone $this;
$clone->uri = $uri;
@@ -696,7 +697,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return array
*/
- public function getCookieParams()
+ public function getCookieParams(): array
{
return $this->cookies;
}
@@ -740,7 +741,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return static
*/
- public function withCookieParams(array $cookies)
+ public function withCookieParams(array $cookies): ServerRequestInterface
{
$clone = clone $this;
$clone->cookies = $cookies;
@@ -760,7 +761,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return array
*/
- public function getQueryParams()
+ public function getQueryParams(): array
{
if (is_array($this->queryParams)) {
return $this->queryParams;
@@ -798,7 +799,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return static
*/
- public function withQueryParams(array $query)
+ public function withQueryParams(array $query): ServerRequestInterface
{
$clone = clone $this;
$clone->queryParams = $query;
@@ -817,7 +818,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return array
*/
- public function getUploadedFiles()
+ public function getUploadedFiles(): array
{
return $this->uploadedFiles;
}
@@ -835,7 +836,7 @@ class Request extends Message implements ServerRequestInterface
*
* @throws InvalidArgumentException if an invalid structure is provided.
*/
- public function withUploadedFiles(array $uploadedFiles)
+ public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
{
$clone = clone $this;
$clone->uploadedFiles = $uploadedFiles;
@@ -852,7 +853,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return array
*/
- public function getServerParams()
+ public function getServerParams(): array
{
return $this->serverParams;
}
@@ -885,7 +886,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return array
*/
- public function getAttributes()
+ public function getAttributes(): array
{
return $this->attributes->all();
}
@@ -929,7 +930,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return static
*/
- public function withAttribute($name, $value)
+ public function withAttribute(string $name, $value): ServerRequestInterface
{
$clone = clone $this;
$clone->attributes->set($name, $value);
@@ -977,7 +978,7 @@ class Request extends Message implements ServerRequestInterface
*
* @return static
*/
- public function withoutAttribute($name)
+ public function withoutAttribute(string $name): ServerRequestInterface
{
$clone = clone $this;
$clone->attributes->remove($name);
@@ -1067,7 +1068,7 @@ class Request extends Message implements ServerRequestInterface
* @throws InvalidArgumentException if an unsupported argument type is
* provided.
*/
- public function withParsedBody($data)
+ public function withParsedBody($data): ServerRequestInterface
{
if (!is_null($data) && !is_object($data) && !is_array($data)) {
throw new InvalidArgumentException('Parsed body value must be an array, an object, or null');
@@ -1208,7 +1209,7 @@ class Request extends Message implements ServerRequestInterface
return $params;
}
-
+
private static function disableXmlEntityLoader($disable)
{
if (\LIBXML_VERSION >= 20900) {
diff --git a/Slim/Http/Response.php b/Slim/Http/Response.php
index f156f70..a25b637 100644
--- a/Slim/Http/Response.php
+++ b/Slim/Http/Response.php
@@ -11,6 +11,7 @@ use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
+use Psr\Http\Message\MessageInterface;
use RuntimeException;
use Slim\Interfaces\Http\HeadersInterface;
@@ -158,7 +159,7 @@ class Response extends Message implements ResponseInterface
*
* @return int
*/
- public function getStatusCode()
+ public function getStatusCode(): int
{
return $this->status;
}
@@ -186,7 +187,7 @@ class Response extends Message implements ResponseInterface
*
* @throws InvalidArgumentException For invalid status code arguments.
*/
- public function withStatus($code, $reasonPhrase = '')
+ public function withStatus($code, $reasonPhrase = ''): ResponseInterface
{
$code = $this->filterStatus($code);
@@ -245,7 +246,7 @@ class Response extends Message implements ResponseInterface
*
* @return string Reason phrase; must return an empty string if none present.
*/
- public function getReasonPhrase()
+ public function getReasonPhrase(): string
{
if ($this->reasonPhrase) {
return $this->reasonPhrase;
@@ -269,7 +270,7 @@ class Response extends Message implements ResponseInterface
*
* @throws InvalidArgumentException For invalid header names or values.
*/
- public function withHeader($name, $value)
+ public function withHeader($name, $value): MessageInterface
{
$clone = clone $this;
$clone->headers->set($name, $value);
diff --git a/Slim/Http/Stream.php b/Slim/Http/Stream.php
index f405dc7..adf6fb1 100644
--- a/Slim/Http/Stream.php
+++ b/Slim/Http/Stream.php
@@ -205,7 +205,7 @@ class Stream implements StreamInterface
/**
* Closes the stream and any underlying resources.
*/
- public function close()
+ public function close(): void
{
if ($this->isAttached() === true) {
if ($this->isPipe()) {
@@ -223,7 +223,7 @@ class Stream implements StreamInterface
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
- public function getSize()
+ public function getSize(): ?int
{
if (!$this->size && $this->isAttached() === true) {
$stats = fstat($this->stream);
@@ -240,7 +240,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException on error.
*/
- public function tell()
+ public function tell(): int
{
if (!$this->isAttached() || ($position = ftell($this->stream)) === false || $this->isPipe()) {
throw new RuntimeException('Could not get the position of the pointer in stream');
@@ -254,7 +254,7 @@ class Stream implements StreamInterface
*
* @return bool
*/
- public function eof()
+ public function eof(): bool
{
return $this->isAttached() ? feof($this->stream) : true;
}
@@ -264,7 +264,7 @@ class Stream implements StreamInterface
*
* @return bool
*/
- public function isReadable()
+ public function isReadable(): bool
{
if ($this->readable === null) {
if ($this->isPipe()) {
@@ -291,7 +291,7 @@ class Stream implements StreamInterface
*
* @return bool
*/
- public function isWritable()
+ public function isWritable(): bool
{
if ($this->writable === null) {
$this->writable = false;
@@ -314,7 +314,7 @@ class Stream implements StreamInterface
*
* @return bool
*/
- public function isSeekable()
+ public function isSeekable(): bool
{
if ($this->seekable === null) {
$this->seekable = false;
@@ -341,7 +341,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException If stream is not seekable
*/
- public function seek($offset, $whence = SEEK_SET)
+ public function seek(int $offset, int $whence = SEEK_SET): void
{
// Note that fseek returns 0 on success!
if (!$this->isSeekable() || fseek($this->stream, $offset, $whence) === -1) {
@@ -361,7 +361,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException on failure.
*/
- public function rewind()
+ public function rewind(): void
{
if (!$this->isSeekable() || rewind($this->stream) === false) {
throw new RuntimeException('Could not rewind stream');
@@ -379,7 +379,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException if an error occurs.
*/
- public function read($length)
+ public function read(int $length): string
{
if (!$this->isReadable() || ($data = fread($this->stream, $length)) === false) {
throw new RuntimeException('Could not read from stream');
@@ -397,7 +397,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException If stream is not writable
*/
- public function write($string)
+ public function write($string): int
{
if (!$this->isWritable() || ($written = fwrite($this->stream, $string)) === false) {
throw new RuntimeException('Could not write to stream');
@@ -416,7 +416,7 @@ class Stream implements StreamInterface
*
* @throws RuntimeException If stream is not readable
*/
- public function getContents()
+ public function getContents(): string
{
if (!$this->isReadable() || ($contents = stream_get_contents($this->stream)) === false) {
throw new RuntimeException('Could not get contents of stream');
diff --git a/Slim/Http/UploadedFile.php b/Slim/Http/UploadedFile.php
index 401440d..53ee39b 100644
--- a/Slim/Http/UploadedFile.php
+++ b/Slim/Http/UploadedFile.php
@@ -180,7 +180,7 @@ class UploadedFile implements UploadedFileInterface
*
* @throws RuntimeException in cases when no stream is available or can be created.
*/
- public function getStream()
+ public function getStream(): StreamInterface
{
if ($this->moved) {
throw new RuntimeException(sprintf('Uploaded file %s has already been moved', $this->name));
@@ -225,7 +225,7 @@ class UploadedFile implements UploadedFileInterface
* @throws InvalidArgumentException If the $path specified is invalid.
* @throws RuntimeException On any error during the move operation or on the second subsequent call to the method.
*/
- public function moveTo($targetPath)
+ public function moveTo(string $targetPath): void
{
if ($this->moved) {
throw new RuntimeException('Uploaded file already moved');
@@ -275,7 +275,7 @@ class UploadedFile implements UploadedFileInterface
*
* @return int
*/
- public function getError()
+ public function getError(): int
{
return $this->error;
}
@@ -292,7 +292,7 @@ class UploadedFile implements UploadedFileInterface
*
* @return string|null
*/
- public function getClientFilename()
+ public function getClientFilename(): ?string
{
return $this->name;
}
@@ -309,7 +309,7 @@ class UploadedFile implements UploadedFileInterface
*
* @return string|null
*/
- public function getClientMediaType()
+ public function getClientMediaType(): ?string
{
return $this->type;
}
@@ -323,7 +323,7 @@ class UploadedFile implements UploadedFileInterface
*
* @return int|null
*/
- public function getSize()
+ public function getSize(): ?int
{
return $this->size;
}
diff --git a/Slim/Http/Uri.php b/Slim/Http/Uri.php
index 57658bb..7419003 100644
--- a/Slim/Http/Uri.php
+++ b/Slim/Http/Uri.php
@@ -247,7 +247,7 @@ class Uri implements UriInterface
*
* @return string The URI scheme.
*/
- public function getScheme()
+ public function getScheme(): string
{
return $this->scheme;
}
@@ -269,7 +269,7 @@ class Uri implements UriInterface
*
* @throws InvalidArgumentException for invalid or unsupported schemes.
*/
- public function withScheme($scheme)
+ public function withScheme(string $scheme): UriInterface
{
$scheme = $this->filterScheme($scheme);
$clone = clone $this;
@@ -327,7 +327,7 @@ class Uri implements UriInterface
*
* @return string The URI authority, in "[user-info@]host[:port]" format.
*/
- public function getAuthority()
+ public function getAuthority(): string
{
$userInfo = $this->getUserInfo();
$host = $this->getHost();
@@ -351,7 +351,7 @@ class Uri implements UriInterface
*
* @return string The URI user information, in "username[:password]" format.
*/
- public function getUserInfo()
+ public function getUserInfo(): string
{
return $this->user . ($this->password !== '' ? ':' . $this->password : '');
}
@@ -371,7 +371,7 @@ class Uri implements UriInterface
*
* @return self A new instance with the specified user information.
*/
- public function withUserInfo($user, $password = null)
+ public function withUserInfo(string $user, ?string $password = null): UriInterface
{
$clone = clone $this;
$clone->user = $this->filterUserInfo($user);
@@ -414,7 +414,7 @@ class Uri implements UriInterface
*
* @return string The URI host.
*/
- public function getHost()
+ public function getHost(): string
{
return $this->host;
}
@@ -431,7 +431,7 @@ class Uri implements UriInterface
*
* @return self A new instance with the specified host.
*/
- public function withHost($host)
+ public function withHost(string $host): UriInterface
{
$clone = clone $this;
$clone->host = $host;
@@ -454,7 +454,7 @@ class Uri implements UriInterface
*
* @return null|int The URI port.
*/
- public function getPort()
+ public function getPort(): ?int
{
return $this->port && !$this->hasStandardPort() ? $this->port : null;
}
@@ -476,7 +476,7 @@ class Uri implements UriInterface
*
* @return self A new instance with the specified port.
*/
- public function withPort($port)
+ public function withPort(?int $port): UriInterface
{
$port = $this->filterPort($port);
$clone = clone $this;
@@ -538,7 +538,7 @@ class Uri implements UriInterface
*
* @return string The URI path.
*/
- public function getPath()
+ public function getPath(): string
{
return $this->path;
}
@@ -566,7 +566,7 @@ class Uri implements UriInterface
*
* @throws InvalidArgumentException For invalid paths.
*/
- public function withPath($path)
+ public function withPath(string $path): UriInterface
{
if (!is_string($path)) {
throw new InvalidArgumentException('Uri path must be a string');
@@ -672,7 +672,7 @@ class Uri implements UriInterface
*
* @return string
*/
- public function getQuery()
+ public function getQuery(): string
{
return $this->query;
}
@@ -694,7 +694,7 @@ class Uri implements UriInterface
*
* @throws InvalidArgumentException For invalid query strings.
*/
- public function withQuery($query)
+ public function withQuery(string $query): UriInterface
{
if (!is_string($query) &&
(!is_object($query) || !method_exists($query, '__toString'))) {
@@ -742,7 +742,7 @@ class Uri implements UriInterface
*
* @return string The URI fragment.
*/
- public function getFragment()
+ public function getFragment(): string
{
return $this->fragment;
}
@@ -762,7 +762,7 @@ class Uri implements UriInterface
*
* @return static A new instance with the specified fragment.
*/
- public function withFragment($fragment)
+ public function withFragment(string $fragment): UriInterface
{
if (!is_string($fragment) &&
(!is_object($fragment) || !method_exists($fragment, '__toString'))) {
@@ -799,7 +799,7 @@ class Uri implements UriInterface
*
* @return string
*/
- public function __toString()
+ public function __toString(): string
{
$scheme = $this->getScheme();
$authority = $this->getAuthority();
diff --git a/composer.json b/composer.json
index bf93955..69e7f70 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
"ext-libxml": "*",
"ext-simplexml": "*",
"pimple/pimple": "^3.0",
- "psr/http-message": "^1.0",
+ "psr/http-message": ">=1 <3",
"nikic/fast-route": "^1.0",
"psr/container": "^2.0"
},
@@ -42,7 +42,7 @@
"phpunit/phpunit": "^4.0"
},
"provide": {
- "psr/http-message-implementation": "1.0"
+ "psr/http-message-implementation": ">=1 <3"
},
"autoload": {
"psr-4": {
|