Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default config (and plugins) #262

Open
soullivaneuh opened this issue Jun 18, 2018 · 4 comments
Open

Default config (and plugins) #262

soullivaneuh opened this issue Jun 18, 2018 · 4 comments

Comments

@soullivaneuh
Copy link
Contributor

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
Copy link
Contributor Author

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.

@Nyholm
Copy link
Member

Nyholm commented Jul 6, 2018

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.

@dbu
Copy link
Collaborator

dbu commented Jul 10, 2018

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 ?

@soullivaneuh
Copy link
Contributor Author

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! 👍

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

No branches or pull requests

3 participants