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

Ability to configure the client by service id. #97

Open
SofHad opened this issue Nov 26, 2015 · 13 comments
Open

Ability to configure the client by service id. #97

SofHad opened this issue Nov 26, 2015 · 13 comments

Comments

@SofHad
Copy link
Contributor

SofHad commented Nov 26, 2015

I think it is very interesting to have ability to configure a client by service id.
(Using a proxy class for example )

csa_guzzle:
    clients:
        github_api:
            service: my_client.service
            config:
                base_url: https://api.github.com
                defaults:
                    headers:
                        Accept: application/vnd.github.v3+json

(I can work on)

@csarrazi
Copy link
Owner

It's actually already possible to do this, and it is documented in the client configuration documentation page.

csa_guzzle:
    clients:
        github_api:
            alias: my_client.service
            config:
                base_url: https://api.github.com
                defaults:
                    headers:
                        Accept: application/vnd.github.v3+json

😉

@csarrazi
Copy link
Owner

Oh, you actually meant being able to specify an existing service defined somewhere else, and configure it using the bundle, right?

@SofHad
Copy link
Contributor Author

SofHad commented Nov 26, 2015

Yes 👍
In case I would overload the configuration for client with constructor.

@csarrazi
Copy link
Owner

Hum, right now, you can already override the class, if needed, by providing the class argument in your client's configuration. But yes, it could be interesting.

csa_guzzle:
    clients:
        github_api:
            class: My\Bundle\Client
            config:
                base_url: https://api.github.com
                defaults:
                    headers:
                        Accept: application/vnd.github.v3+json

@SofHad
Copy link
Contributor Author

SofHad commented Nov 26, 2015

the idea is, to merge the configuration coming from '_csa_guzzle_' with the Client constructor arguments.

@csarrazi
Copy link
Owner

Hum, this will be complicated, and it may prove difficult to prevent BC on such a feature.

I would suggest to take the problem by the other side, by using a compiler pass to extend the original guzzle service, instead, adding additional arguments, method calls, etc.
Or decorating the Guzzle service with your own service, which is done by most implementors.

The problem with such a feature is that it may prevent us from implementing other features which I very much want here, like a param converter to inject a response from an API call, and serialization.

For this, we need to make sure that the client actually returns what is expected, which is a PSR-7 response or request, or a promise, depending depending on the method being called.

@SofHad
Copy link
Contributor Author

SofHad commented Nov 26, 2015

I thought of a proxy class with a magic method __call ?

@SofHad
Copy link
Contributor Author

SofHad commented Nov 26, 2015

Or using https://github.com/Ocramius/ProxyManager ?

@csarrazi
Copy link
Owner

Possible. But in that case, I would actually inject the configured API client, instead. :)

@csarrazi
Copy link
Owner

But regardless, why not!

@SofHad
Copy link
Contributor Author

SofHad commented Nov 26, 2015

ping @Arthurhall

@csarrazi
Copy link
Owner

csarrazi commented Dec 1, 2015

Any news on this? :)

@SofHad
Copy link
Contributor Author

SofHad commented Dec 2, 2015

I didn't have time to work on it :)

I would suggest to take the problem by the other side, by using a compiler pass to extend the original guzzle service, instead, adding additional arguments, method calls, etc.
Or decorating the Guzzle service with your own service, which is done by most implementors.

Config example:

# config.yml
csa_guzzle:
    clients:
        github_api:
            config:
                service: foo.client
                base_url: https://api.github.com
                overwrite: true  # whether overwrite the MyClient config
                defaults:
                    proxy: foo
                    headers:
                        Accept: application/vnd.github.v3+json
services:
    foo.client:
        class: Acme\AppBundle\MyClient
        arguments: [{proxy: bar}, @baz, %foo.param%]
        public: true

I don't see how to merge both configurations using the compiler pass?
I see 2 solutions, doing this with Middleware (override the Request configuration) or using the proxy design pattern ?

@csarrazi csarrazi added this to the v2.1.0 milestone Feb 12, 2016
@csarrazi csarrazi modified the milestones: v2.2.0, v2.1.0 May 24, 2016
@csarrazi csarrazi modified the milestones: v2.2.0, v2.3.0 Feb 8, 2017
@csarrazi csarrazi removed this from the v2.3.0 milestone Dec 6, 2017
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