diff --git a/composer.json b/composer.json index 3f4e9bb..0090531 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,12 @@ "php": "^5.5 || ^7.0", "symfony/options-resolver": "^2.6 || ^3.0", "php-http/httplug": "^1.0", - "php-http/message-factory": "^1.0.2", - "php-http/discovery": "^1.0" + "guzzlehttp/psr7": "^1.2" }, "require-dev": { "phpunit/phpunit": "^4.8", - "guzzlehttp/psr7": "^1.2", "php-http/client-integration-tests": "^0.5.1", + "php-http/message-factory": "^1.0.2", "php-http/message": "^1.0", "php-http/client-common": "^1.0" }, diff --git a/src/Client.php b/src/Client.php index 4ab7bc5..646d563 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,7 +4,6 @@ use Http\Client\Exception\NetworkException; use Http\Client\HttpClient; -use Http\Discovery\MessageFactoryDiscovery; use Http\Message\ResponseFactory; use Psr\Http\Message\RequestInterface; use Symfony\Component\OptionsResolver\Options; @@ -22,6 +21,11 @@ class Client implements HttpClient use RequestWriter; use ResponseReader; + /** + * Config of this client. + * + * @var array + */ private $config = [ 'remote_socket' => null, 'timeout' => null, @@ -35,8 +39,7 @@ class Client implements HttpClient /** * Constructor. * - * @param ResponseFactory $responseFactory Response factory for creating response - * @param array $config { + * @param array $config { * * @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address) * @var int $timeout Timeout before canceling request @@ -46,15 +49,21 @@ class Client implements HttpClient * @var int $write_buffer_size Buffer when writing the request body, defaults to 8192 * @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLS_CLIENT * } + * + * @param array $deprecatedConfig Use for BC with old versions */ - public function __construct(ResponseFactory $responseFactory = null, array $config = []) + public function __construct($config = [], array $deprecatedConfig = []) { - if (null === $responseFactory) { - $responseFactory = MessageFactoryDiscovery::find(); + if ($config instanceof ResponseFactory || $config === null) { + // To remove in 2.0 + trigger_error( + 'Injecting a request factory is no longer required, as this lib directly use guzzlehttp/psr7 implementation', + E_USER_DEPRECATED + ); + $this->config = $this->configure($deprecatedConfig); + } else { + $this->config = $this->configure($config); } - - $this->responseFactory = $responseFactory; - $this->config = $this->configure($config); } /** diff --git a/src/ResponseReader.php b/src/ResponseReader.php index 202d1bd..7c968e0 100644 --- a/src/ResponseReader.php +++ b/src/ResponseReader.php @@ -2,8 +2,8 @@ namespace Http\Client\Socket; +use GuzzleHttp\Psr7\Response; use Http\Client\Exception\NetworkException; -use Http\Message\ResponseFactory; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -16,11 +16,6 @@ */ trait ResponseReader { - /** - * @var ResponseFactory For creating response - */ - protected $responseFactory; - /** * Read a response from a socket. * @@ -77,7 +72,7 @@ protected function readResponse(RequestInterface $request, $socket) : ''; } - $response = $this->responseFactory->createResponse($status, $reason, $responseHeaders, null, $protocol); + $response = new Response($status, $responseHeaders, null, $protocol, $reason); $stream = $this->createStream($socket, $response); return $response->withBody($stream); diff --git a/tests/SocketHttpClientTest.php b/tests/SocketHttpClientTest.php index c3660ec..1db2729 100644 --- a/tests/SocketHttpClientTest.php +++ b/tests/SocketHttpClientTest.php @@ -12,7 +12,7 @@ public function createClient($options = array()) { $messageFactory = new GuzzleMessageFactory(); - return new HttpMethodsClient(new SocketHttpClient($messageFactory, $options), $messageFactory); + return new HttpMethodsClient(new SocketHttpClient($options), $messageFactory); } public function testTcpSocketDomain()