Skip to content

Commit

Permalink
ref #6609 Plugins can provide their own config files
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Feb 9, 2015
1 parent e084b06 commit a028d17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 19 additions & 4 deletions core/Container/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Common\Cache\ArrayCache;
use Piwik\Config;
use Piwik\Development;
use Piwik\Plugin\Manager;

/**
* Creates a configured DI container.
Expand Down Expand Up @@ -41,10 +42,6 @@ public function __construct($environment = null)
*/
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);
Expand All @@ -56,6 +53,9 @@ public function create()
// 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');
Expand All @@ -82,4 +82,19 @@ private function addEnvironmentConfig(ContainerBuilder $builder)

$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);
}
}
}
12 changes: 10 additions & 2 deletions core/Plugin/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Piwik\Singleton;
use Piwik\Theme;
use Piwik\Tracker;
use Piwik\Translate;
use Piwik\Translation\Translator;
use Piwik\Updater;
use Piwik\Plugin\Dimension\ActionDimension;
Expand Down Expand Up @@ -98,7 +97,7 @@ class Manager extends Singleton
*/
public function loadActivatedPlugins()
{
$pluginsToLoad = Config::getInstance()->Plugins['Plugins'];
$pluginsToLoad = $this->getActivatedPluginsFromConfig();
$this->loadPlugins($pluginsToLoad);
}

Expand Down Expand Up @@ -778,6 +777,15 @@ public function getActivatedPlugins()
return $this->pluginsToLoad;
}

public function getActivatedPluginsFromConfig()
{
$plugins = Config::getInstance()->Plugins['Plugins'];

$plugins = $this->sortPluginsSameOrderAsGlobalConfig($plugins);

return $plugins;
}

/**
* Returns a Plugin object by name.
*
Expand Down

0 comments on commit a028d17

Please sign in to comment.