diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-02-02 01:04:02 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-02-10 00:56:03 +0300 |
commit | a028d179e99221149466661f0d7c73feebd348d2 (patch) | |
tree | c0685381ebb739c33147189aac5a51edf552c3ce | |
parent | e084b065d0b8abd8684fb74be4d1e0e66db33f74 (diff) |
ref #6609 Plugins can provide their own config files
-rw-r--r-- | core/Container/ContainerFactory.php | 23 | ||||
-rw-r--r-- | core/Plugin/Manager.php | 12 |
2 files changed, 29 insertions, 6 deletions
diff --git a/core/Container/ContainerFactory.php b/core/Container/ContainerFactory.php index bf3b157ba8..4098b1e204 100644 --- a/core/Container/ContainerFactory.php +++ b/core/Container/ContainerFactory.php @@ -13,6 +13,7 @@ use DI\ContainerBuilder; use Doctrine\Common\Cache\ArrayCache; use Piwik\Config; use Piwik\Development; +use Piwik\Plugin\Manager; /** * Creates a configured DI container. @@ -41,10 +42,6 @@ class ContainerFactory */ public function create() { - if (!class_exists('DI\ContainerBuilder')) { - throw new \Exception('DI\ContainerBuilder could not be found, maybe you are using Piwik from git and need to update Composer: php composer.phar update'); - } - $builder = new ContainerBuilder(); $builder->useAnnotations(false); @@ -56,6 +53,9 @@ class ContainerFactory // Global config $builder->addDefinitions(PIWIK_USER_PATH . '/config/global.php'); + // Plugin configs + $this->addPluginConfigs($builder); + // Development config if (Development::isEnabled()) { $builder->addDefinitions(PIWIK_USER_PATH . '/config/environment/dev.php'); @@ -82,4 +82,19 @@ class ContainerFactory $builder->addDefinitions($file); } + + private function addPluginConfigs(ContainerBuilder $builder) + { + $plugins = Manager::getInstance()->getActivatedPluginsFromConfig(); + + foreach ($plugins as $plugin) { + $file = Manager::getPluginsDirectory() . $plugin . '/config/config.php'; + + if (! file_exists($file)) { + continue; + } + + $builder->addDefinitions($file); + } + } } diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index fd7b02837f..6b7181d829 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -24,7 +24,6 @@ use Piwik\Plugin; use Piwik\Singleton; use Piwik\Theme; use Piwik\Tracker; -use Piwik\Translate; use Piwik\Translation\Translator; use Piwik\Updater; use Piwik\Plugin\Dimension\ActionDimension; @@ -98,7 +97,7 @@ class Manager extends Singleton */ public function loadActivatedPlugins() { - $pluginsToLoad = Config::getInstance()->Plugins['Plugins']; + $pluginsToLoad = $this->getActivatedPluginsFromConfig(); $this->loadPlugins($pluginsToLoad); } @@ -778,6 +777,15 @@ class Manager extends Singleton return $this->pluginsToLoad; } + public function getActivatedPluginsFromConfig() + { + $plugins = Config::getInstance()->Plugins['Plugins']; + + $plugins = $this->sortPluginsSameOrderAsGlobalConfig($plugins); + + return $plugins; + } + /** * Returns a Plugin object by name. * |