From 5020c7098ca6661d7c2ef9f1f6248b335eeb941b Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sun, 31 Jul 2016 16:01:41 +0200 Subject: [PATCH 1/3] Remove message factory and use a concrete implementation (guzzle) --- composer.json | 11 +++++------ src/Client.php | 24 ++++++++++++++++-------- src/ResponseReader.php | 9 ++------- tests/SocketHttpClientTest.php | 2 +- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 3f4e9bb..a2115d1 100644 --- a/composer.json +++ b/composer.json @@ -12,15 +12,14 @@ "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": "^1.0", - "php-http/client-common": "^1.0" + "php-http/adapter-integration-tests": "~0.3.1", + "php-http/client-common": "^1.0", + "php-http/message-factory": "^1.0.2", + "puli/composer-plugin": "1.0.0-beta9" }, "provide": { "php-http/client-implementation": "1.0" diff --git a/src/Client.php b/src/Client.php index 4ab7bc5..7644b06 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,7 +39,6 @@ class Client implements HttpClient /** * Constructor. * - * @param ResponseFactory $responseFactory Response factory for creating response * @param array $config { * * @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address) @@ -46,15 +49,20 @@ 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() From 004d3fccf3ca807db8052abebcc04cac13998d30 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sun, 31 Jul 2016 16:09:09 +0200 Subject: [PATCH 2/3] Fix cs --- src/Client.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 7644b06..646d563 100644 --- a/src/Client.php +++ b/src/Client.php @@ -22,7 +22,7 @@ class Client implements HttpClient use ResponseReader; /** - * Config of this client + * Config of this client. * * @var array */ @@ -39,7 +39,7 @@ class Client implements HttpClient /** * Constructor. * - * @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 @@ -49,7 +49,8 @@ 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 + * + * @param array $deprecatedConfig Use for BC with old versions */ public function __construct($config = [], array $deprecatedConfig = []) { From 9dad9eccebeb34263137484b77948e5f76e272cb Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sun, 31 Jul 2016 16:24:08 +0200 Subject: [PATCH 3/3] Fix deps --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a2115d1..0090531 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,10 @@ }, "require-dev": { "phpunit/phpunit": "^4.8", - "php-http/adapter-integration-tests": "~0.3.1", - "php-http/client-common": "^1.0", + "php-http/client-integration-tests": "^0.5.1", "php-http/message-factory": "^1.0.2", - "puli/composer-plugin": "1.0.0-beta9" + "php-http/message": "^1.0", + "php-http/client-common": "^1.0" }, "provide": { "php-http/client-implementation": "1.0"