diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-03-16 08:24:04 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-03-16 08:24:04 +0300 |
commit | 20e002f56268de91db6eeb86dce92591bc387c05 (patch) | |
tree | 8cf2aa725511be10463bccff1f7282d27e4eba16 /core | |
parent | 0bbc42c4a88a3083b89a4b5c611024c02060f0db (diff) | |
parent | a7a8c7173a9bef6a67006e5e463c1cdcfbd27b23 (diff) |
Merge pull request #7408 from piwik/di-in-widgets-menus-tasks
Dependency injection in widgets, menus, settings and tasks
Diffstat (limited to 'core')
-rw-r--r-- | core/Plugin.php | 3 | ||||
-rw-r--r-- | core/Plugin/Menu.php | 17 | ||||
-rw-r--r-- | core/Plugin/Widgets.php | 14 |
3 files changed, 8 insertions, 26 deletions
diff --git a/core/Plugin.php b/core/Plugin.php index af564a002b..bb361b5bb5 100644 --- a/core/Plugin.php +++ b/core/Plugin.php @@ -8,6 +8,7 @@ */ namespace Piwik; +use Piwik\Container\StaticContainer; use Piwik\Plugin\Dependency; use Piwik\Plugin\MetadataLoader; @@ -359,7 +360,7 @@ class Plugin $this->cache->save($cacheId, $classname); } - return new $classname; + return StaticContainer::get($classname); } public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass) diff --git a/core/Plugin/Menu.php b/core/Plugin/Menu.php index d2c54645f1..e354728821 100644 --- a/core/Plugin/Menu.php +++ b/core/Plugin/Menu.php @@ -30,16 +30,6 @@ use Piwik\Plugins\UsersManager\UserPreferences; */ class Menu { - protected $module = ''; - - /** - * @ignore - */ - public function __construct() - { - $this->module = $this->getModule(); - } - private function getModule() { $className = get_class($this); @@ -69,7 +59,7 @@ class Menu { $params = (array) $additionalParams; $params['action'] = ''; - $params['module'] = $this->module; + $params['module'] = $this->getModule(); return $params; } @@ -88,11 +78,12 @@ class Menu */ protected function urlForAction($controllerAction, $additionalParams = array()) { - $this->checkisValidCallable($this->module, $controllerAction); + $module = $this->getModule(); + $this->checkisValidCallable($module, $controllerAction); $params = (array) $additionalParams; $params['action'] = $controllerAction; - $params['module'] = $this->module; + $params['module'] = $module; return $params; } diff --git a/core/Plugin/Widgets.php b/core/Plugin/Widgets.php index 36081fe2d2..5a0cad6fde 100644 --- a/core/Plugin/Widgets.php +++ b/core/Plugin/Widgets.php @@ -25,16 +25,6 @@ class Widgets protected $category = ''; protected $widgets = array(); - private $module = ''; - - /** - * @ignore - */ - public function __construct() - { - $this->module = $this->getModule(); - } - /** * @ignore */ @@ -77,7 +67,7 @@ class Widgets 'name' => $name, 'params' => $parameters, 'method' => $method, - 'module' => $this->module); + 'module' => $this->getModule()); } /** @@ -182,7 +172,7 @@ class Widgets return; } - $controllerClass = '\\Piwik\\Plugins\\' . $this->module . '\\Controller'; + $controllerClass = 'Piwik\\Plugins\\' . $this->getModule() . '\\Controller'; if (!Development::methodExists($this, $method) && !Development::methodExists($controllerClass, $method)) { |