8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

Autowiring GuzzleHttp\ClientInterface does not work out of the box (as per documentation) #312

Closed Starojitski closed 3 years ago

Starojitski commented 3 years ago

Followed installation instructions:

eight_points_guzzle:
    clients:
        default:
            options:
                http_errors: false

But when running website get the following exception

image

Defining service and alias helped but would rather not have to do this, if possible. Any advice?

        <service id="GuzzleHttp\ClientInterface" alias="eight_points_guzzle.client.default"/>
        <service id="eight_points_guzzle.client.default" class="GuzzleHttp\Client" />
Q A
Symfony version 4.4.32
Bundle version 8.2.0

PS, Autowiring Client instead of ClientInterface does work

gregurco commented 3 years ago

Hello @Starojitski,

Yep, we know about this problem. You can read more about autowiring in this bundle here: https://github.com/8p/EightPointsGuzzleBundle/blob/master/src/Resources/doc/autowiring-clients.md

I think it's possible to activate autowiring if you have just one client. I will check how to do that. Thanks for idea 👍

Starojitski commented 3 years ago

Thanks for such fast reply! But the thing is that I had read the resource you refer to and according to it there should not be any need to define services and aliases. Or am i mistaken?

Edit: From what i understood all i had to do was to define a client, which i called default, and that should have been enough

gregurco commented 3 years ago

@Starojitski check here: https://github.com/8p/EightPointsGuzzleBundle/blob/master/src/DependencyInjection/EightPointsGuzzleExtension.php#L101 We create alias by type and name. So if you want to autowire by ClientInterface you have to use $defaultClient name. I will check if we can do it without reserved name and only by type.

Starojitski commented 3 years ago

Yes, I realize now that I have not actually read the documentation on autowiring, but only looked at the provided code snippets. I wonder whether I am the only one that functions that way.

My apologies and thanks for your patience with me!