You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Store references in plugins array
* Introduce PluginConfigurator
This allows for configuring plugins via the normal config.
When you have a plugin that does not require config, the old behavior is the easiest.
But when you do want custom config per client, it will be cumbersome to create separate services
and reference them everywhere.
It would be easier to have the same type of configuration as the built-in clients.
That's now possible with the PluginConfigurator.
Define the plugins as follows:
```yaml
'plugins' => [
[
'configurator' => [
'id' => CustomPluginConfigurator::class,
'config' => [
'name' => 'foo',
]
],
],
],
```
The `CustomPluginConfigurator` looks like this:
```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']);
}
}
```
On compile time, the config will be evaluated. It will create the service definition
by calling the `create` method with the given config.
On runtime you will have the CustomPlugin instantiated with the custom config.
0 commit comments