From 0ab3269cad7896df8bc95958617504f8875ae808 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Sat, 23 Nov 2024 12:00:38 +0100 Subject: [PATCH 1/2] Explain PluginConfigurator See https://github.com/php-http/HttplugBundle/pull/477 --- integrations/symfony-bundle.rst | 43 +++++++++++++++++++++ integrations/symfony-full-configuration.rst | 6 +++ 2 files changed, 49 insertions(+) diff --git a/integrations/symfony-bundle.rst b/integrations/symfony-bundle.rst index c531ddb..da95470 100644 --- a/integrations/symfony-bundle.rst +++ b/integrations/symfony-bundle.rst @@ -403,6 +403,49 @@ client: plugins: - 'acme_plugin' +If you want to configure your plugin using the bundle configuration, you can +create a class that implements PluginConfigurator. + + +.. code-block:: php + + final class CustomPluginConfigurator implements PluginConfigurator + { + public static function getConfigTreeBuilder() : TreeBuilder + { + $treeBuilder = new TreeBuilder('custom_plugin'); + $rootNode = $treeBuilder->getRootNode(); + + $rootNode + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->end(); + + return $treeBuilder; + } + + public function create(array $config) : CustomPlugin + { + return new CustomPlugin($config['name']); + } + } + +.. code-block:: yaml + + // config.yml + httplug: + clients: + acme: + factory: 'httplug.factory.guzzle6' + plugins: + - configurator: + id: 'App\CustomPluginConfigurator' + config: + name: 'foo' + Authentication -------------- diff --git a/integrations/symfony-full-configuration.rst b/integrations/symfony-full-configuration.rst index 95a6a91..ffc63fb 100644 --- a/integrations/symfony-full-configuration.rst +++ b/integrations/symfony-full-configuration.rst @@ -113,6 +113,12 @@ This page shows an example of all configuration values provided by the bundle. plugins: # Can reference a globally configured plugin service - 'httplug.plugin.authentication.my_wsse' + # Configure a plugin using a custom PluginConfigurator + - configurator: + id: App\Httplug\Plugin\MyPluginConfigurator + config: + foo: 'bar' + baz: 'qux' # Can configure a plugin customized for this client - cache: cache_pool: 'my_other_pool' From 64aecb2bbfcaa6f201a01b565b2d78e821d52fb2 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 24 Nov 2024 09:50:09 +0100 Subject: [PATCH 2/2] Update integrations/symfony-bundle.rst --- integrations/symfony-bundle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/symfony-bundle.rst b/integrations/symfony-bundle.rst index da95470..4d161e0 100644 --- a/integrations/symfony-bundle.rst +++ b/integrations/symfony-bundle.rst @@ -404,7 +404,7 @@ client: - 'acme_plugin' If you want to configure your plugin using the bundle configuration, you can -create a class that implements PluginConfigurator. +create a class that implements ``PluginConfigurator`` and define ``configurator`` plugins. .. code-block:: php