Cannot create the client using `HttpClientDiscovery`
hpatoio opened this issue · comments
I'm trying to create a small library usign php-http
.
Here the composer.json
{
"require": {
"php-http/message": "^1.2",
"php-http/client-common": "^1.1",
"php-http/discovery": "^0.8.0",
"puli/composer-plugin": "^1.0@beta,>=1.0.0-beta9"
},
"require-dev": {
"php-http/curl-client": "^1.4"
},
"minimum-stability": "beta"
}
I run composer install
and all vendors are installed
I've then created a simple demo.php
file with this code:
include_once('vendor/autoload.php');
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
$httpClient = HttpClientDiscovery::find();
echo get_class($httpClient);
but I get
PHP Catchable fatal error: Argument 1 passed to Http\Client\Curl\Client::__construct() must be an instance of Http\Message\MessageFactory, none given, called in /var/www/demo-library/vendor/php-http/discovery/src/HttpClientDiscovery.php on line 23 and defined in /var/www/demo-library/vendor/php-http/curl-client/src/Client.php on line 72
That seems correct because Http\Client\Curl\Client
is declared as
public function __construct(
MessageFactory $messageFactory,
StreamFactory $streamFactory,
array $options = []
) {
$this->messageFactory = $messageFactory;
$this->streamFactory = $streamFactory;
$this->options = $options;
}
Am I doing something wrong ?
Hm, it seems that the Curl client requires the factories in the constructor. Normally they should be optional and use the respective discovery in the constructor if any of them are not passed. I fear the curl client is currently incompatible with the discovery layer.
I'll check this at mondey.
Fixed in 1.4.1.
Also note that you need to add PSR7 implementation to the "require" list, as described in the documentation.