Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You cannot use the "Symfony\Component\HttpClient\Psr18Client" as the "psr/http-client" package is not installed #248

Closed
brettmc opened this issue Jun 16, 2023 · 6 comments · Fixed by #249

Comments

@brettmc
Copy link

brettmc commented Jun 16, 2023

PHP version: 8.2.0

Description
php-http/discovery plugin installs a psr18 client that cannot be discovered

How to reproduce
composer.json:

{
  "config": {
    "allow-plugins": {
      "php-http/discovery": true
    }
  },
  "require": {
    "php-http/client-implementation": "^1.0",
    "php-http/discovery": "^1.18"
  }
}

test.php:

<?php
require 'vendor/autoload.php';
$client = \Http\Discovery\Psr18ClientDiscovery::find();
var_dump(get_class($client));
composer update
php test.php

Results:

Fatal error: Uncaught LogicException: You cannot use the "Symfony\Component\HttpClient\Psr18Client" as the "psr/http-client" package is not installed. Try running "composer require php-http/discovery psr/http-client-implementation:*". in /usr/src/myapp/vendor/symfony/http-client/Psr18Client.php on line 37

Possible Solution
As a workaround, I could require psr/http-client, but we don't directly require or use it.

@dbu
Copy link
Contributor

dbu commented Jun 16, 2023

ok, took me a moment but i think this is a confusion between the psr client and the legacy php-http client abstraction.

if you want psr-18, you don't need to require php-http/client-implementation but psr/http-client-implementation

@dbu
Copy link
Contributor

dbu commented Jun 16, 2023

if you manually require psr/http-client, it will only work by chance because the symfony http client has adapters for both http client interfaces.

@brettmc
Copy link
Author

brettmc commented Jun 17, 2023

Changing my requirements to use psr/http-client-implementation gives the same error:

{
  "config": {
    "allow-plugins": {
      "php-http/discovery": true
    }
  },
  "require": {
    "psr/http-client-implementation": "*",
    "php-http/discovery": "^1.18"
  }
}

But, I was mistaken earlier when I said we did not directly rely on psr/http-client - we do, and so I should add that dependency to our library.

I'd like to understand better about "it will only work by chance" though, I'd much prefer it to work on purpose! :)

@dbu
Copy link
Contributor

dbu commented Jun 17, 2023

php-http/client-implementation is the virtual package for the httplug interfaces by php-http. after we built that, we proposed psr-18, which is now accepted and defines an "official" http client interface. the virtual package for psr18 is psr/http-client-implementation.

we did not deprecate httplug because it also provides an asynchronous client, and psr-18 is only about synchronous http requests.

symfony/http-client provides both an integration with psr18 and with the legacy php-http client - this is why i said it would work by chance if you requries a php-http client implementation but then expect to find a psr18 client.

all that said, i just ran your minimal composer.json and indeed psr/http-client is not installed automatically. i think this is indeed a mistake of discovery. i think #249 would be the fix. can you try with that branch if your project then indeed works?

@brettmc
Copy link
Author

brettmc commented Jun 17, 2023

Confirmed as working using dev-composer-plugin branch. I get psr/http-client, and discovery works as expected.

@dbu dbu closed this as completed in #249 Jun 19, 2023
@dbu
Copy link
Contributor

dbu commented Jun 19, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants