Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Add documentation for symfony service injection in the guzzle client #52

Open
csarrazi opened this issue Sep 8, 2015 · 3 comments
Open

Comments

@csarrazi
Copy link
Owner

csarrazi commented Sep 8, 2015

With release 1.3.2, symfony services can now be injected in a client's configuration.

This should be documented in the 1.3 branch.

@rvanlaak
Copy link
Contributor

rvanlaak commented Aug 22, 2018

Another use case to document; changing the client's class, and how to autowire that to another own service definition.

We use the bundle as "a factory" for our own autowireable class:

<?php

namespace Acme\Infra\Shopping;

class Client extends \GuzzleHttp\Client
{
}
csa_guzzle:
    clients:
        shopping:
            class: 'Acme\Infra\Shopping\Client'
            config:
                base_uri: '%shopping.base_uri%'

... and we want to autowire that class in our own service definition:

services:
    Acme\Application\Shopping\Cart:
        arguments: ['@Acme\Infra\Shopping\Client']   

For controller action argument autowiring this works perfectly, but for resolving service arguments on container compilation this unfortunately gives a "service not found" exception because the bundle registers the client to the container after it resolves the rest of the services.

Probably the solution is somewhere in compilation priorities. It would be great to have documentation on this, as the above allows everyone to make use of all the great middleware the bundle can register with the clients.

A way the container can resolve / autowire is by aliasing the service this bundle creates:

services:
    Acme\Infra\Shopping\Client:
        alias: 'csa_guzzle.client.shopping'

@csarrazi
Copy link
Owner Author

Good point, however that would be in another issue. Do you mind creating a new issue from your comment? That would be great! :)

@rvanlaak
Copy link
Contributor

Of course 👍 see #236

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

No branches or pull requests

2 participants