Configure client with custom class
Closed this issue · 3 comments
Q | A |
---|---|
Bug? | no |
New Feature? | yes |
Version | 1.13.0 |
We use Symfony 4 auto-wiring. To make it easier to inject the right client inside the service it would be great if I could specify the class name per httplug client.
This feature is supported by EightPointGuzzleBundle and allows you to do something like this:
httplug:
clients:
acme:
classes:
client: 'My\Custom\HttpClient'
I looked at HTTPlug and I see that it uses factories to get this done. I could of course create a factory for every single httplug client, but that feels like a lot of work.
Wondering if there is a better way? I'm willing to create a PR.
I think this can be fairly easy by just adding a decorating service definition when class
configuration node is set.
You can always do something like this:
# config/services.yaml
services:
My\Custom\HttpClient: ~
# config/httplug.yaml
httplug:
clients:
my_client:
service: 'My\Custom\HttpClient'
as per discussion in the pull request: use the symfony service decoration feature which is more flexible than building something specific into this bundle.