8p / EightPointsGuzzleBundle

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

Plugins #21

Closed ghost closed 9 years ago

ghost commented 9 years ago

I can't seem to find a way to addl handlers, plugins, Middleware or even add additional events to the guzzle package. I have a use-case where in I need to be able to change an authentication header, and I'd like to provide a plugin that can handle the work. However; I don't see how to make it work currently.

My initial thought was to try and add the plugin but I don't see how that is loaded. Then I tried to add it through a compiler pass; but since I don't have access to the options being set on the client I can't do that. My second thought was to create a handler on the guzzle stack, that would emit events, and then bind to handlers/listeners using tags.

Would this be something you where interested in?

florianpreusner commented 9 years ago

Added handler stack as a service so you can now add your own middlewares/plugins. You can get this version by setting the repo in composer.json:

"repositories": [
    {
        "url":  "https://github.com/florianpreusner/GuzzleBundle.git",
        "type": "git"
    }
],

"require": {    
    "eightpoints/guzzle-bundle": "dev-master"
}

After getting this version you should be able to get the guzzle handler stack by the container and add your own middlewares:

$stack = $this->get('guzzle.handler_stack.NAME_OF_CLIENT_BY_CONFIG');
$stack->push($callable);

Please check if that fits your request. If so I can integrate this change and also provide a documentation.

Best regards Florian

ghost commented 9 years ago

I have a patch I've written that actually dispatches an event.

Sent from my iPhone

On Sep 19, 2015, at 6:08 PM, Florian Preusner notifications@github.com wrote:

Added handler stack as a service so you can now add your own middlewares/plugins. You can get this version by setting the repo in composer.json:

"repositories": [ { "url": "https://github.com/florianpreusner/GuzzleBundle.git", "type": "git" } ],

"require": {
"eightpoints/guzzle-bundle": "dev-master" } After getting this version you should be able to get the guzzle handler stack by the container and add your own middlewares:

$stack = $this->get('guzzle.handler_stack.NAME_OF_CLIENT_BY_CONFIG'); $stack->push($callable); Please check if that fits your request. If so I can integrate this change and also provide a documentation.

Best regards Florian

— Reply to this email directly or view it on GitHub.

florianpreusner commented 9 years ago

Can you share some more information cause your idea to be able to push middlewares to the handler stack seems to be interesting for others also.

quadland commented 9 years ago

@florianpreusner That pull request is the enhancement I spoke of.

Chris Warner

florianpreusner commented 9 years ago

I see. Great! Thanks for your contribution, your PR is merged.

MLKiiwy commented 8 years ago

Hello,

I try to add some middleware in my guzzle client, but your service id for handler doesn't exist anymore. And if I see your code your system that create handler is totally static we can't add handler ?