diff options
-rw-r--r-- | core/Plugin.php | 3 | ||||
-rw-r--r-- | core/Plugin/Menu.php | 17 | ||||
-rw-r--r-- | core/Plugin/Widgets.php | 14 | ||||
-rw-r--r-- | plugins/CoreHome/Widgets.php | 17 |
4 files changed, 22 insertions, 29 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)) { diff --git a/plugins/CoreHome/Widgets.php b/plugins/CoreHome/Widgets.php index 68812f0749..17d888bd35 100644 --- a/plugins/CoreHome/Widgets.php +++ b/plugins/CoreHome/Widgets.php @@ -10,12 +10,23 @@ namespace Piwik\Plugins\CoreHome; use Piwik\Common; use Piwik\Piwik; +use Piwik\Translation\Translator; use Piwik\View; class Widgets extends \Piwik\Plugin\Widgets { protected $category = 'Example Widgets'; + /** + * @var Translator + */ + private $translator; + + public function __construct(Translator $translator) + { + $this->translator = $translator; + } + protected function init() { $this->addWidget('CoreHome_SupportPiwik', 'getDonateForm'); @@ -31,7 +42,7 @@ class Widgets extends \Piwik\Plugin\Widgets if (Common::getRequestVar('widget', false) && Piwik::hasUserSuperUserAccess()) { - $view->footerMessage = Piwik::translate('CoreHome_OnlyForSuperUserAccess'); + $view->footerMessage = $this->translator->translate('CoreHome_OnlyForSuperUserAccess'); } return $view->render(); @@ -43,8 +54,8 @@ class Widgets extends \Piwik\Plugin\Widgets public function getPromoVideo() { $view = new View('@CoreHome/getPromoVideo'); - $view->shareText = Piwik::translate('CoreHome_SharePiwikShort'); - $view->shareTextLong = Piwik::translate('CoreHome_SharePiwikLong'); + $view->shareText = $this->translator->translate('CoreHome_SharePiwikShort'); + $view->shareTextLong = $this->translator->translate('CoreHome_SharePiwikLong'); $view->promoVideoUrl = 'https://www.youtube.com/watch?v=OslfF_EH81g'; return $view->render(); |