Skip to content

Commit e564aee

Browse files
committed
#25: Make discovery a hard dependency
1 parent f06bc47 commit e564aee

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

composer.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
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"
2422
},
2523
"require-dev": {
2624
"guzzlehttp/psr7": "^1.0",
2725
"php-http/client-integration-tests": "^0.5.1",
28-
"php-http/discovery": "^1.0",
2926
"phpunit/phpunit": "^4.8",
3027
"zendframework/zend-diactoros": "^1.0"
3128
},

src/Client.php

+2-22
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
*/
2727
class Client implements HttpClient, HttpAsyncClient
2828
{
29-
/**
30-
* @access private
31-
*/
32-
const DEPENDENCY_MSG = 'You should either provide $%s argument or install "php-http/discovery"';
33-
3429
/**
3530
* cURL options
3631
*
@@ -73,7 +68,6 @@ class Client implements HttpClient, HttpAsyncClient
7368
* @param StreamFactory|null $streamFactory HTTP Stream factory
7469
* @param array $options cURL options (see http://php.net/curl_setopt)
7570
*
76-
* @throws \LogicException If some factory not provided and php-http/discovery not installed
7771
* @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed.
7872
*
7973
* @since 1.0
@@ -83,22 +77,8 @@ public function __construct(
8377
StreamFactory $streamFactory = null,
8478
array $options = []
8579
) {
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;
101-
80+
$this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find();
81+
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
10282
$this->options = $options;
10383
}
10484

0 commit comments

Comments
 (0)