Skip to content

Commit 3c0212d

Browse files
committed
Make discovery a hard dependency
1 parent f06bc47 commit 3c0212d

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
"ext-curl": "*",
1818
"php-http/httplug": "^1.0",
1919
"php-http/message-factory": "^1.0.2",
20-
"php-http/message": "^1.2"
21-
},
22-
"suggest": {
23-
"php-http/discovery": "Allow automatically discover needed HTTPlug implementations"
20+
"php-http/message": "^1.2",
21+
"php-http/discovery": "^1.0"
22+
2423
},
2524
"require-dev": {
2625
"guzzlehttp/psr7": "^1.0",
2726
"php-http/client-integration-tests": "^0.5.1",
28-
"php-http/discovery": "^1.0",
2927
"phpunit/phpunit": "^4.8",
3028
"zendframework/zend-diactoros": "^1.0"
3129
},

src/Client.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Http\Client\HttpClient;
88
use Http\Discovery\MessageFactoryDiscovery;
99
use Http\Discovery\StreamFactoryDiscovery;
10-
use Http\Message\MessageFactory;
10+
use Http\Message\ResponseFactory;
1111
use Http\Message\StreamFactory;
1212
use Http\Promise\Promise;
1313
use Psr\Http\Message\RequestInterface;
@@ -39,11 +39,11 @@ class Client implements HttpClient, HttpAsyncClient
3939
private $options;
4040

4141
/**
42-
* PSR-7 message factory
42+
* PSR-7 response factory
4343
*
44-
* @var MessageFactory
44+
* @var ResponseFactory
4545
*/
46-
private $messageFactory;
46+
private $responseFactory;
4747

4848
/**
4949
* PSR-7 stream factory
@@ -69,35 +69,22 @@ class Client implements HttpClient, HttpAsyncClient
6969
/**
7070
* Create new client
7171
*
72-
* @param MessageFactory|null $messageFactory HTTP Message factory
73-
* @param StreamFactory|null $streamFactory HTTP Stream factory
74-
* @param array $options cURL options (see http://php.net/curl_setopt)
72+
* @param ResponseFactory|null $responseFactory HTTP Response factory
73+
* @param StreamFactory|null $streamFactory HTTP Stream factory
74+
* @param array $options cURL options (see http://php.net/curl_setopt)
7575
*
7676
* @throws \LogicException If some factory not provided and php-http/discovery not installed
7777
* @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed.
7878
*
7979
* @since 1.0
8080
*/
8181
public function __construct(
82-
MessageFactory $messageFactory = null,
82+
ResponseFactory $responseFactory = null,
8383
StreamFactory $streamFactory = null,
8484
array $options = []
8585
) {
86-
if (null === $messageFactory) {
87-
if (!class_exists(MessageFactoryDiscovery::class)) {
88-
throw new \LogicException(sprintf(self::DEPENDENCY_MSG, 'messageFactory'));
89-
}
90-
$messageFactory = MessageFactoryDiscovery::find();
91-
}
92-
$this->messageFactory = $messageFactory;
93-
94-
if (null === $streamFactory) {
95-
if (!class_exists(StreamFactoryDiscovery::class)) {
96-
throw new \LogicException(sprintf(self::DEPENDENCY_MSG, 'streamFactory'));
97-
}
98-
$streamFactory = StreamFactoryDiscovery::find();
99-
}
100-
$this->streamFactory = $streamFactory;
86+
$this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find();
87+
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
10188

10289
$this->options = $options;
10390
}
@@ -344,7 +331,7 @@ private function createResponseBuilder()
344331
} catch (\InvalidArgumentException $e) {
345332
throw new \RuntimeException('Can not create "php://temp" stream.');
346333
}
347-
$response = $this->messageFactory->createResponse(200, null, [], $body);
334+
$response = $this->responseFactory->createResponse(200, null, [], $body);
348335

349336
return new ResponseBuilder($response);
350337
}

0 commit comments

Comments
 (0)