Skip to content

Commit 9709aad

Browse files
Adds the \Stringable interface to classes that have __toString() method (#5920)
Co-authored-by: 李铭昕 <[email protected]>
1 parent 9d72369 commit 9709aad

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

src/Base/Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
use Psr\Http\Message\RequestInterface;
1818
use Psr\Http\Message\StreamInterface;
1919
use Psr\Http\Message\UriInterface;
20+
use Stringable;
2021
use Swow\Psr7\Message\RequestPlusInterface;
2122

22-
class Request implements RequestInterface, RequestPlusInterface
23+
class Request implements RequestInterface, RequestPlusInterface, Stringable
2324
{
2425
use MessageTrait;
2526

src/Base/Response.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
use InvalidArgumentException;
1515
use Psr\Http\Message\ResponseInterface;
16+
use Stringable;
1617
use Swow\Psr7\Message\ResponsePlusInterface;
1718

18-
class Response implements ResponseInterface, ResponsePlusInterface
19+
class Response implements ResponseInterface, ResponsePlusInterface, Stringable
1920
{
2021
use MessageTrait;
2122

src/Server/ResponsePlusProxy.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313

1414
use Psr\Http\Message\ResponseInterface;
1515
use Psr\Http\Message\StreamInterface;
16+
use Stringable;
1617
use Swow\Psr7\Message\ResponsePlusInterface;
1718

18-
class ResponsePlusProxy implements ResponsePlusInterface
19+
class ResponsePlusProxy implements ResponsePlusInterface, Stringable
1920
{
2021
public function __construct(protected ResponseInterface $response)
2122
{
2223
}
2324

24-
public function __toString()
25+
public function __toString(): string
2526
{
2627
return $this->toString();
2728
}

src/Upload/UploadedFile.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
use Psr\Http\Message\UploadedFileInterface;
1818
use RuntimeException;
1919
use SplFileInfo;
20+
use Stringable;
2021

21-
class UploadedFile extends SplFileInfo implements UploadedFileInterface
22+
class UploadedFile extends SplFileInfo implements UploadedFileInterface, Stringable
2223
{
2324
/**
2425
* @var int[]

src/Uri/Uri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Stringable;
1717
use Swow\Psr7\Message\UriPlusInterface;
1818

19-
class Uri implements UriInterface, Stringable, UriPlusInterface
19+
class Uri implements UriInterface, UriPlusInterface, Stringable
2020
{
2121
/**
2222
* Absolute http and https URIs require a host per RFC 7230 Section 2.7

tests/SwooleStreamTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Mockery;
1919
use PHPUnit\Framework\Attributes\CoversNothing;
2020
use PHPUnit\Framework\TestCase;
21+
use Stringable;
2122
use Swoole\Http\Response as SwooleResponse;
2223

2324
/**
@@ -182,4 +183,11 @@ public function testGetContents()
182183

183184
$this->assertSame($random, $stream->getContents());
184185
}
186+
187+
public function testInstanceOfStringable()
188+
{
189+
$random = microtime();
190+
$stream = new SwooleStream($random);
191+
$this->assertInstanceOf(Stringable::class, $stream);
192+
}
185193
}

0 commit comments

Comments
 (0)