Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like us to have any dependency on Guzzle.

(except for dev-requirements)

},
"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"
},
Expand Down
27 changes: 18 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/ResponseReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,11 +16,6 @@
*/
trait ResponseReader
{
/**
* @var ResponseFactory For creating response
*/
protected $responseFactory;

/**
* Read a response from a socket.
*
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/SocketHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down