Skip to content

Commit 0243e0c

Browse files
committed
Use only psr18 and not httplug anymore, fix psr7 implementation
1 parent ed21563 commit 0243e0c

13 files changed

+58
-74
lines changed

composer.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
],
1111
"require": {
1212
"php": "^7.1",
13-
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0",
14-
"php-http/httplug": "^1.0 || ^2.0",
15-
"php-http/message-factory": "^1.0.2 || ^2.0",
16-
"php-http/discovery": "^1.0"
13+
"nyholm/psr7": "^1.0",
14+
"psr/http-client": "^1.0",
15+
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0"
1716
},
1817
"require-dev": {
1918
"friendsofphp/php-cs-fixer": "^2.2",
20-
"guzzlehttp/psr7": "^1.2",
21-
"php-http/client-integration-tests": "^1.0 || ^2.0",
19+
"php-http/client-integration-tests": "^2.0",
2220
"php-http/message": "^1.0",
23-
"php-http/client-common": "^1.0 || ^2.0"
21+
"php-http/client-common": "^2.0"
2422
},
2523
"provide": {
2624
"php-http/client-implementation": "1.0"

src/Client.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Http\Client\Socket\Exception\ConnectionException;
77
use Http\Client\Socket\Exception\InvalidRequestException;
88
use Http\Client\Socket\Exception\SSLConnectionException;
9-
use Http\Discovery\MessageFactoryDiscovery;
10-
use Http\Message\ResponseFactory;
119
use Psr\Http\Message\RequestInterface;
1210
use Psr\Http\Message\ResponseInterface;
1311
use Symfony\Component\OptionsResolver\Options;
@@ -38,8 +36,7 @@ class Client implements HttpClient
3836
/**
3937
* Constructor.
4038
*
41-
* @param ResponseFactory $responseFactory Response factory for creating response
42-
* @param array $config {
39+
* @param array $config {
4340
*
4441
* @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address)
4542
* @var int $timeout Timeout before canceling request
@@ -50,13 +47,8 @@ class Client implements HttpClient
5047
* @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
5148
* }
5249
*/
53-
public function __construct(ResponseFactory $responseFactory = null, array $config = [])
50+
public function __construct(array $config = [])
5451
{
55-
if (null === $responseFactory) {
56-
$responseFactory = MessageFactoryDiscovery::find();
57-
}
58-
59-
$this->responseFactory = $responseFactory;
6052
$this->config = $this->configure($config);
6153
}
6254

src/Exception/BrokenPipeException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
use Http\Client\Exception\NetworkException;
6-
75
class BrokenPipeException extends NetworkException
86
{
97
}

src/Exception/ConnectionException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
use Http\Client\Exception\NetworkException;
6-
75
class ConnectionException extends NetworkException
86
{
97
}

src/Exception/InvalidRequestException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
use Http\Client\Exception\NetworkException;
6-
75
class InvalidRequestException extends NetworkException
86
{
97
}

src/Exception/NetworkException.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Http\Client\Socket\Exception;
4+
5+
use Psr\Http\Client\NetworkExceptionInterface;
6+
use Psr\Http\Message\RequestInterface;
7+
8+
class NetworkException extends \RuntimeException implements NetworkExceptionInterface
9+
{
10+
private $request;
11+
12+
public function __construct(string $message, RequestInterface $request, \Exception $previous = null)
13+
{
14+
$this->request = $request;
15+
16+
parent::__construct($message, 0, $previous);
17+
}
18+
19+
public function getRequest(): RequestInterface
20+
{
21+
return $this->request;
22+
}
23+
}

src/Exception/SSLConnectionException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
use Http\Client\Exception\NetworkException;
6-
75
class SSLConnectionException extends NetworkException
86
{
97
}

src/Exception/StreamException.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,8 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
use Http\Client\Exception;
6-
use Psr\Http\Message\RequestInterface;
5+
use Psr\Http\Client\ClientExceptionInterface;
76

8-
class StreamException extends \RuntimeException implements Exception
7+
class StreamException extends \RuntimeException implements ClientExceptionInterface
98
{
10-
/**
11-
* The request object.
12-
*
13-
* @var RequestInterface
14-
*/
15-
private $request;
16-
17-
/**
18-
* Accepts an optional request object as 4th param.
19-
*
20-
* @param string $message
21-
* @param int $code
22-
* @param Exception $previous
23-
* @param RequestInterface $request
24-
*/
25-
public function __construct($message = null, $code = null, $previous = null, RequestInterface $request = null)
26-
{
27-
$this->request = $request;
28-
parent::__construct($message, $code, $previous);
29-
}
30-
31-
/**
32-
* @return \Psr\Http\Message\RequestInterface|null
33-
*/
34-
final public function getRequest()
35-
{
36-
return $this->request;
37-
}
389
}

src/Exception/TimeoutException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace Http\Client\Socket\Exception;
44

5-
class TimeoutException extends StreamException
5+
class TimeoutException extends NetworkException
66
{
77
}

src/ResponseReader.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Http\Client\Socket\Exception\BrokenPipeException;
66
use Http\Client\Socket\Exception\TimeoutException;
77
use Http\Message\ResponseFactory;
8+
use Nyholm\Psr7\Response;
89
use Psr\Http\Message\RequestInterface;
910
use Psr\Http\Message\ResponseInterface;
1011

@@ -76,8 +77,8 @@ protected function readResponse(RequestInterface $request, $socket): ResponseInt
7677
: '';
7778
}
7879

79-
$response = $this->responseFactory->createResponse($status, $reason, $responseHeaders, null, $protocol);
80-
$stream = $this->createStream($socket, $response);
80+
$response = new Response($status, $responseHeaders, null, $protocol, $reason);
81+
$stream = $this->createStream($socket, $request, $response);
8182

8283
return $response->withBody($stream);
8384
}
@@ -87,14 +88,14 @@ protected function readResponse(RequestInterface $request, $socket): ResponseInt
8788
*
8889
* @param resource $socket
8990
*/
90-
protected function createStream($socket, ResponseInterface $response): Stream
91+
protected function createStream($socket, RequestInterface $request, ResponseInterface $response): Stream
9192
{
9293
$size = null;
9394

9495
if ($response->hasHeader('Content-Length')) {
9596
$size = (int) $response->getHeaderLine('Content-Length');
9697
}
9798

98-
return new Stream($socket, $size);
99+
return new Stream($request, $socket, $size);
99100
}
100101
}

0 commit comments

Comments
 (0)