Skip to content

Psr18ClientDiscovery with the Symfony Http Client throws a LogicException #171

Closed
@matt-allan

Description

@matt-allan

PHP version: 7.4.5

Description

With symfony/http-client and nyholm/psr7 installed, calling Psr18ClientDiscovery::find() results in the following LogicException being thrown:

PHP Fatal error:  Uncaught LogicException: You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug". in /Users/matt/code/discovery-repro/vendor/symfony/http-client/HttplugClient.php:44
Stack trace:
#0 /Users/matt/code/discovery-repro/vendor/composer/ClassLoader.php(444): include()
#1 /Users/matt/code/discovery-repro/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/Users/matt/cod...')
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...')
#3 [internal function]: spl_autoload_call('Symfony\\Compone...')
#4 /Users/matt/code/discovery-repro/vendor/php-http/discovery/src/Strategy/CommonClassesStrategy.php(115): is_subclass_of('Symfony\\Compone...', 'Psr\\Http\\Client...')
#5 [internal function]: Http\Discovery\Strategy\CommonClassesStrategy::getCandidates('Psr\\Http\\Client...')
#6 /Users/matt/code/discovery-repro/vendor/php-http/discovery/src/ClassDiscovery.php(56): call_user_ in /Users/matt/code/discovery-repro/vendor/symfony/http-client/HttplugClient.php on line 44

How to reproduce

composer.json:

{
    "require": {
        "php-http/discovery": "^1.7",
        "psr/http-message": "^1.0",
        "psr/http-factory": "^1.0",
        "psr/http-client": "^1.0",
        "nyholm/psr7": "^1.2",
        "symfony/http-client": "^5.0"
    }
}

index.php:

<?php

use Http\Discovery\Psr18ClientDiscovery;

require __DIR__.'/vendor/autoload.php';

$client = Psr18ClientDiscovery::find();

var_dump($client);
composer install
php ./index.php

Possible Solution

See #170

Additional context

The error seems to indicate Discovery is trying to load Symfony\Component\HttpClient\HttplugClient instead of Symfony\Component\HttpClient\Psr18Client.

I pushed an example here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions