From f05bf69d5055b1ac21ba8cc41391f819b78fc583 Mon Sep 17 00:00:00 2001 From: magarzon Date: Fri, 31 Jul 2015 01:37:08 +0100 Subject: [PATCH 1/2] Added extension prepend configuration to plugins --- src/BundlePlugin.php | 9 +++++++++ src/ExtensionWithPlugins.php | 15 ++++++++++++++- src/SimpleBundlePlugin.php | 9 +++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/BundlePlugin.php b/src/BundlePlugin.php index 4059e78..d0e317e 100644 --- a/src/BundlePlugin.php +++ b/src/BundlePlugin.php @@ -55,4 +55,13 @@ public function build(ContainerBuilder $container); * @return void */ public function boot(ContainerInterface $container); + + /** + * When the container is generated for the first time, this method is called + * to give an opportunity to prepend configuration for this or other bundles + * + * @param ContainerInterface $container + * @return void + */ + public function prepend(ContainerBuilder $container); } diff --git a/src/ExtensionWithPlugins.php b/src/ExtensionWithPlugins.php index be42ec0..94f71c5 100644 --- a/src/ExtensionWithPlugins.php +++ b/src/ExtensionWithPlugins.php @@ -3,9 +3,10 @@ namespace Matthias\BundlePlugins; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -final class ExtensionWithPlugins extends Extension +final class ExtensionWithPlugins extends Extension implements PrependExtensionInterface { /** * @var string @@ -86,4 +87,16 @@ private function pluginConfiguration(BundlePlugin $plugin, array $processedConfi return $processedConfiguration[$plugin->name()]; } + + /** + * Allow an extension to prepend the extension configurations. + * + * @param ContainerBuilder $container + */ + public function prepend(ContainerBuilder $container) + { + foreach ($this->registeredPlugins as $plugin) { + $plugin->prepend($container); + } + } } diff --git a/src/SimpleBundlePlugin.php b/src/SimpleBundlePlugin.php index e83c7c8..a74163a 100644 --- a/src/SimpleBundlePlugin.php +++ b/src/SimpleBundlePlugin.php @@ -37,4 +37,13 @@ public function build(ContainerBuilder $container) public function boot(ContainerInterface $container) { } + + /** + * Override this method if your plugin needs to prepend configuration + * + * @inheritdoc + */ + public function prepend(ContainerBuilder $container) + { + } } From 28546c566e3e98a929c1bff06d1dfd137a402c2c Mon Sep 17 00:00:00 2001 From: magarzon Date: Fri, 31 Jul 2015 01:39:10 +0100 Subject: [PATCH 2/2] Added prepend methods to test plugins, so test are not broken --- test/BarPlugin.php | 4 ++++ test/CorePlugin.php | 4 ++++ test/FooPlugin.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/test/BarPlugin.php b/test/BarPlugin.php index 5bc3d49..c2d0532 100644 --- a/test/BarPlugin.php +++ b/test/BarPlugin.php @@ -40,4 +40,8 @@ public function boot(ContainerInterface $container) { $container->get('bar.boot')->call(); } + + public function prepend(ContainerBuilder $container) + { + } } diff --git a/test/CorePlugin.php b/test/CorePlugin.php index 4ff2fb3..d9d9c64 100644 --- a/test/CorePlugin.php +++ b/test/CorePlugin.php @@ -42,4 +42,8 @@ public function boot(ContainerInterface $container) { $container->get('core.boot')->call(); } + + public function prepend(ContainerBuilder $container) + { + } } diff --git a/test/FooPlugin.php b/test/FooPlugin.php index e2aaeb3..46e1b6f 100644 --- a/test/FooPlugin.php +++ b/test/FooPlugin.php @@ -40,4 +40,8 @@ public function boot(ContainerInterface $container) { $container->get('foo.boot')->call(); } + + public function prepend(ContainerBuilder $container) + { + } }