HttplugBundle icon indicating copy to clipboard operation
HttplugBundle copied to clipboard

Default config (and plugins)

Open soullivaneuh opened this issue 7 years ago • 4 comments

Q A
Bug? no
New Feature? yes
Version 1.10.0

Actual Behavior

On each client we configure, we have to define the plugins we want. In case of plugin we want everywhere, we have to repeat the configuration on each of them.

Expected Behavior

The idea is to allow a common client configuration to be applied on each defined client.

With that, we will be able to define common plugin setup with ease. We can also think about it for other option like http_methods_client.

Sample:

httplug:
    default:
        http_methods_client: true
        plugins:
            - 'httplug.plugin.logger'
    clients:
        default:
            factory: 'httplug.factory.guzzle6'
            config:
                timeout: 5
        cacheable:
            factory: 'httplug.factory.guzzle6'
            plugins:
                - 'httplug.plugin.cache'
        dummy:
            factory: 'httplug.factory.guzzle6'
            http_methods_client: false
    profiling:
        captured_body_length: 1000

What do you think?

soullivaneuh avatar Jun 18 '18 08:06 soullivaneuh

Current workaround with yaml anchors:

httplug:
    plugins:
        cache:
            # Should be the auto-wired service.
            # @see https://github.com/php-http/HttplugBundle/issues/263
            cache_pool: 'cache.app'
    clients:
        default: &default
            factory: 'httplug.factory.guzzle6'
            config: &default_config
                timeout: 15
            http_methods_client: true
            plugins:
                - 'httplug.plugin.cache'
        default_v6:
            <<: *default
            config:
                <<: *default_config
                force_ip_resolve: v6

    profiling:
        captured_body_length: 1000

But it's not very pretty and works only with YAML.

soullivaneuh avatar Jul 06 '18 09:07 soullivaneuh

That is some cool yaml. I've never seen that.

I agree with the "default" section. Look how Symfony Messenger does it. They had "middlewares_before" and "middlewares_after". That might make sense here as well.

Nyholm avatar Jul 06 '18 14:07 Nyholm

agreed, i like the proposal and @Nyholm input. lets have plugins_before and plugins_after. that was the first question i asked myself looking at the example: how do we control the order, as order can matter with the plugins.

do you want to work on this @Soullivaneuh ?

dbu avatar Jul 10 '18 06:07 dbu

That is some cool yaml. I've never seen that.

@Nyholm This is Yaml anchors. It is mentioned on the spec: https://yaml.org/spec/1.2.2/#3222-anchors-and-aliases

And you can find several samples on the web, for example: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

It is cool but can be quickly very verbose and has some limitations, especially for array values management: https://stackoverflow.com/q/4948933

lets have plugins_before and plugins_after. that was the first question i asked myself looking at the example: how do we control the order, as order can matter with the plugins.

I agree with that.

do you want to work on this @soullivaneuh ?

I may, but I don't know when. As the need is strictly related to the company where I work and the workaround looks enough so far, it is not yet planned.

I suggest to keep the issue open, feel free to any-one taking care of it! :+1:

soullivaneuh avatar Oct 31 '23 14:10 soullivaneuh