Skip to content

Commit e2d3906

Browse files
committed
make compatible with stream interface
1 parent 4a69954 commit e2d3906

5 files changed

+21
-36
lines changed

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
}
1010
],
1111
"require": {
12-
"php": "^7.2 || ^8.0",
13-
"nyholm/psr7": "^1.3",
14-
"php-http/httplug": "^2.0",
12+
"php": "^7.4 || ^8.0",
13+
"nyholm/psr7": "^1.8.1",
14+
"php-http/httplug": "^2.4",
1515
"psr/http-client": "^1.0",
1616
"symfony/options-resolver": "^2.6 || ^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0"
1717
},
1818
"require-dev": {
19-
"friendsofphp/php-cs-fixer": "^2.2 || ^3.0",
19+
"friendsofphp/php-cs-fixer": "^3.51",
2020
"php-http/client-integration-tests": "^3.0",
21-
"php-http/message": "^1.9",
22-
"php-http/client-common": "^2.3",
21+
"php-http/message": "^1.16",
22+
"php-http/client-common": "^2.7",
2323
"phpunit/phpunit": "^8.5.23 || ~9.5"
2424
},
2525
"provide": {

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<testsuites>
99
<testsuite name="Socket Client Test Suite">
1010
<directory>tests/</directory>
11-
<exclude>tests/SocketClientFeatureTest.php</exclude>
1211
</testsuite>
1312
</testsuites>
1413
<php>

src/ResponseReader.php

-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Http\Client\Socket\Exception\BrokenPipeException;
66
use Http\Client\Socket\Exception\TimeoutException;
7-
use Http\Message\ResponseFactory;
87
use Nyholm\Psr7\Response;
98
use Psr\Http\Message\RequestInterface;
109
use Psr\Http\Message\ResponseInterface;
@@ -18,11 +17,6 @@
1817
*/
1918
trait ResponseReader
2019
{
21-
/**
22-
* @var ResponseFactory For creating response
23-
*/
24-
protected $responseFactory;
25-
2620
/**
2721
* Read a response from a socket.
2822
*

src/Stream.php

+13-19
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(RequestInterface $request, $socket, ?int $size = nul
6161
$this->request = $request;
6262
}
6363

64-
public function __toString()
64+
public function __toString(): string
6565
{
6666
try {
6767
return $this->getContents();
@@ -70,7 +70,7 @@ public function __toString()
7070
}
7171
}
7272

73-
public function close()
73+
public function close(): void
7474
{
7575
if ($this->isDetached || null === $this->socket) {
7676
throw new StreamException('Stream is detached');
@@ -93,12 +93,12 @@ public function detach()
9393
/**
9494
* @return int<0, max>|null
9595
*/
96-
public function getSize()
96+
public function getSize(): ?int
9797
{
9898
return $this->size;
9999
}
100100

101-
public function tell()
101+
public function tell(): int
102102
{
103103
if ($this->isDetached || null === $this->socket) {
104104
throw new StreamException('Stream is detached');
@@ -111,7 +111,7 @@ public function tell()
111111
return $tell;
112112
}
113113

114-
public function eof()
114+
public function eof(): bool
115115
{
116116
if ($this->isDetached || null === $this->socket) {
117117
throw new StreamException('Stream is detached');
@@ -120,46 +120,40 @@ public function eof()
120120
return feof($this->socket);
121121
}
122122

123-
public function isSeekable()
123+
public function isSeekable(): bool
124124
{
125125
return false;
126126
}
127127

128-
/**
129-
* @return void
130-
*/
131-
public function seek($offset, $whence = SEEK_SET)
128+
public function seek($offset, $whence = SEEK_SET): void
132129
{
133130
throw new StreamException('This stream is not seekable');
134131
}
135132

136-
/**
137-
* @return void
138-
*/
139-
public function rewind()
133+
public function rewind(): void
140134
{
141135
throw new StreamException('This stream is not seekable');
142136
}
143137

144-
public function isWritable()
138+
public function isWritable(): bool
145139
{
146140
return false;
147141
}
148142

149-
public function write($string)
143+
public function write($string): int
150144
{
151145
throw new StreamException('This stream is not writable');
152146
}
153147

154-
public function isReadable()
148+
public function isReadable(): bool
155149
{
156150
return true;
157151
}
158152

159153
/**
160154
* @param int<0, max> $length
161155
*/
162-
public function read($length)
156+
public function read($length): string
163157
{
164158
if ($this->isDetached || null === $this->socket) {
165159
throw new StreamException('Stream is detached');
@@ -197,7 +191,7 @@ public function read($length)
197191
return $read;
198192
}
199193

200-
public function getContents()
194+
public function getContents(): string
201195
{
202196
if ($this->isDetached || null === $this->socket) {
203197
throw new StreamException('Stream is detached');

tests/SocketHttpClientTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
use Http\Client\Socket\Client as SocketHttpClient;
77
use Http\Client\Socket\Exception\NetworkException;
88
use Http\Client\Socket\Exception\TimeoutException;
9-
use Http\Message\MessageFactory\GuzzleMessageFactory;
9+
use Nyholm\Psr7\Factory\Psr17Factory;
1010

1111
class SocketHttpClientTest extends BaseTestCase
1212
{
1313
public function createClient($options = [])
1414
{
15-
$messageFactory = new GuzzleMessageFactory();
16-
17-
return new HttpMethodsClient(new SocketHttpClient($options), $messageFactory);
15+
return new HttpMethodsClient(new SocketHttpClient($options), new Psr17Factory());
1816
}
1917

2018
public function testTcpSocketDomain()

0 commit comments

Comments
 (0)