"php-http/httplug" package is not installed
rpayanm opened this issue · comments
PHP version: 7.4.16
Description
I installed this library:
https://symfony.com/doc/4.4/http_client.html
I am using it, but when I run this code:
use Symfony\Component\HttpClient\HttplugClient;
$httpClient = new HttplugClient();
I got this error:
You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug".
Here the output of composer show | egrep "symfony|php-http
php-http/httplug 2.2.0 HTTPlug, the HTTP cl...
php-http/message-factory v1.0.2 Factory interfaces f...
php-http/promise 1.1.0 Promise used for asy...
symfony-cmf/routing 2.3.3 Extends the Symfony ...
symfony/console v4.4.25 Eases the creation o...
symfony/css-selector v5.3.0 Converts CSS selecto...
symfony/debug v4.4.25 Provides tools to ea...
symfony/dependency-injection v4.4.25 Allows you to standa...
symfony/deprecation-contracts v2.4.0 A generic function a...
symfony/error-handler v4.4.25 Provides tools to ma...
symfony/event-dispatcher v4.4.25 Provides tools that ...
symfony/event-dispatcher-contracts v1.1.9 Generic abstractions...
symfony/filesystem v4.4.26 Provides basic utili...
symfony/finder v5.3.0 Finds files and dire...
symfony/http-client v4.4.26 Provides powerful me...
symfony/http-client-contracts v2.4.0 Generic abstractions...
symfony/http-foundation v4.4.25 Defines an object-or...
symfony/http-kernel v4.4.25 Provides a structure...
symfony/mime v5.3.0 Allows manipulating ...
symfony/polyfill-ctype v1.23.0 Symfony polyfill for...
symfony/polyfill-iconv v1.23.0 Symfony polyfill for...
symfony/polyfill-intl-idn v1.23.0 Symfony polyfill for...
symfony/polyfill-intl-normalizer v1.23.0 Symfony polyfill for...
symfony/polyfill-mbstring v1.23.0 Symfony polyfill for...
symfony/polyfill-php72 v1.23.0 Symfony polyfill bac...
symfony/polyfill-php73 v1.23.0 Symfony polyfill bac...
symfony/polyfill-php80 v1.23.0 Symfony polyfill bac...
symfony/process v4.4.25 Executes commands in...
symfony/psr-http-message-bridge v2.1.0 PSR HTTP message bridge
symfony/routing v4.4.25 Maps an HTTP request...
symfony/serializer v4.4.25 Handles serializing ...
symfony/service-contracts v2.4.0 Generic abstractions...
symfony/translation v4.4.25 Provides tools to in...
symfony/translation-contracts v2.4.0 Generic abstractions...
symfony/validator v4.4.25 Provides tools to va...
symfony/var-dumper v5.3.0 Provides mechanisms ...
symfony/yaml v4.4.25 Loads and dumps YAML...
This sounds like an exception being raised by Symfony. The bug is probably with them.
The code behind: HttplugClient
class is:
if (!interface_exists(HttplugInterface::class)) {
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug".');
}
if (!interface_exists(RequestFactory::class)) {
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/message-factory" package is not installed. Try running "composer require nyholm/psr7".');
}
/**
* An adapter to turn a Symfony HttpClientInterface into an Httplug client.
*
* Run "composer require nyholm/psr7" to install an efficient implementation of response
* and stream factories with flex-provided autowiring aliases.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
{
If I put in my code:
if (!interface_exists(HttplugInterface::class)) {
// Some code.
}
The code inside de if
always executes.
yep, as the code says. if you want to instantiate the symfony client HttpPlugClient adapter, you need to require php-http/httplug.
if you use the symfony framework, just typehint Symfony\Contracts\HttpClient\HttpClientInterface to get injected the right client.
if you don't care what client you use, i'd recommend to instantiate the curl client or native stream client as explained at:
https://symfony.com/doc/4.4/http_client.html#enabling-curl-support
yep, as the code says. if you want to instantiate the symfony client HttpPlugClient adapter, you need to require php-http/httplug.
It is installed, see the output of my composer show
on my first comment.
Can you please share your composer.json
file?
Yes, sure:
{
"name": "drupal/recommended-project",
"description": "Project template for Drupal 9 projects with a relocated document root",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"composer/installers": "^1.9",
"cweagans/composer-patches": "^1.7",
"drupal/admin_toolbar": "^3.0",
"drupal/block_field": "^1.0@RC",
"drupal/core-composer-scaffold": "^9.1",
"drupal/core-project-message": "^9.1",
"drupal/core-recommended": "^9.1",
"drupal/editor_advanced_link": "^1.8",
"drupal/editor_file": "^1.5",
"drupal/entity_embed": "^1.1",
"drupal/entity_usage": "^2.0@beta",
"drupal/feeds": "^3.0@alpha",
"drupal/field_config_cardinality": "^1.1",
"drupal/field_group": "^3.1",
"drupal/gtm": "^1.6",
"drupal/link_attributes": "^1.11",
"drupal/mailsystem": "^4.3",
"drupal/metatag": "^1.16",
"drupal/owlcarousel": "^1.0@alpha",
"drupal/paragraphs": "^1.12",
"drupal/paragraphs_ee": "^1.7",
"drupal/paragraphs_features": "^1.11",
"drupal/pathauto": "^1.8",
"drupal/quicklink": "^2.0@beta",
"drupal/rabbit_hole": "^1.0@beta",
"drupal/redirect": "^1.6",
"drupal/scheduler": "^1.3",
"drupal/search_api": "^1.19",
"drupal/sendgrid_integration": "^1.7",
"drupal/simple_recaptcha": "^1.0@beta",
"drupal/simple_sitemap": "^3.10",
"drupal/structured_data": "^1.2",
"drupal/swiftmailer": "^2.0",
"drupal/token": "^1.9",
"drupal/token_filter": "^1.2",
"drupal/twig_field_value": "^2.0",
"drupal/twig_tweak": "^3.0",
"drupal/views_accordion": "^2.0",
"drupal/views_slideshow": "^4.8",
"drupal/webform": "^6.0",
"drush/drush": "^10.4",
"guzzlehttp/promises": "^1.4",
"nyholm/psr7": "^1.3",
"php-http/httplug": "^2.2",
"symfony/http-client": "^4.4"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"web/profiles/custom/{$name}": [
"type:drupal-custom-profile"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-core-project-message": {
"include-keys": [
"homepage",
"support"
],
"post-create-project-cmd-message": [
"<bg=blue;fg=white> </>",
"<bg=blue;fg=white> Congratulations, you’ve installed the Drupal codebase </>",
"<bg=blue;fg=white> from the drupal/recommended-project template! </>",
"<bg=blue;fg=white> </>",
"",
"<bg=yellow;fg=black>Next steps</>:",
" * Install the site: https://www.drupal.org/docs/8/install",
" * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
" * Get support: https://www.drupal.org/support",
" * Get involved with the Drupal community:",
" https://www.drupal.org/getting-involved",
" * Remove the plugin that prints this message:",
" composer remove drupal/core-project-message"
]
}
}
}
sorry, i overlooked that you have php-http/httplug installed.
but then it sounds like an issue with autoloading or something.
looking at https://github.com/symfony/http-client/blob/5.3/HttplugClient.php, i see that the "HttplugInterface" is an alias from our HttpClient interface. when you tried in your own code, did you also create the alias?