diff options
author | Fabian Becker <halfdan@xnorfz.de> | 2013-10-01 01:41:13 +0400 |
---|---|---|
committer | Fabian Becker <halfdan@xnorfz.de> | 2013-10-01 01:41:13 +0400 |
commit | db6add11e5ec204ca25722d245d23add63b0816c (patch) | |
tree | d513f776d39f9a73455f70e309eb0380ffbb44a3 | |
parent | b79c18f59eb6ba5ec30a195a71bb8c67bbd5aeb5 (diff) | |
parent | d7a33219e4b84bc2e1a552de16b5433415d12b3d (diff) |
Merge pull request #111 from piwik/registry
Removing Zend_Registry from Core
fixes #4188
-rw-r--r-- | core/Controller.php | 4 | ||||
-rw-r--r-- | core/ExceptionHandler.php | 2 | ||||
-rw-r--r-- | core/FrontController.php | 8 | ||||
-rw-r--r-- | core/Log.php | 2 | ||||
-rw-r--r-- | core/Piwik.php | 4 | ||||
-rw-r--r-- | core/Registry.php | 64 | ||||
-rw-r--r-- | core/Tracker.php | 1 | ||||
-rw-r--r-- | core/View.php | 4 | ||||
-rw-r--r-- | plugins/LanguagesManager/Controller.php | 3 | ||||
-rw-r--r-- | plugins/Login/Login.php | 8 | ||||
-rw-r--r-- | plugins/Overlay/API.php | 2 | ||||
-rw-r--r-- | plugins/UsersManager/API.php | 6 | ||||
-rw-r--r-- | tests/PHPUnit/DatabaseTestCase.php | 2 | ||||
-rwxr-xr-x | tests/PHPUnit/IntegrationTestCase.php | 2 |
14 files changed, 87 insertions, 25 deletions
diff --git a/core/Controller.php b/core/Controller.php index 7837bdd4ca..cebbc105a2 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -20,9 +20,9 @@ use Piwik\Plugins\API\API; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API as APIUsersManager; +use Piwik\Registry; use Piwik\View; use Piwik\ViewDataTable; -use Zend_Registry; /** * Parent class of all plugins Controllers (located in /plugins/PluginName/Controller.php @@ -611,7 +611,7 @@ abstract class Controller && $currentLogin != 'anonymous' ) { $errorMessage = sprintf(Piwik_Translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user $currentLogin'>", "</a>"); - $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . \Zend_Registry::get('auth')->getName() . "&action=logout'>› " . Piwik_Translate('General_Logout') . "</a></b><br />"; + $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik_Translate('General_Logout') . "</a></b><br />"; Piwik_ExitWithMessage($errorMessage, false, true); } diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 26ecef6a00..13cca7f35d 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -62,4 +62,4 @@ class ExceptionHandler { Log::error($exception); } -}
\ No newline at end of file +} diff --git a/core/FrontController.php b/core/FrontController.php index de341ec971..e748c3346b 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -14,7 +14,7 @@ use Exception; use Piwik\API\Request; use Piwik\API\ResponseBuilder; use Piwik\Session; -use Zend_Registry; +use Piwik\Registry; /** * Front controller. @@ -168,7 +168,7 @@ class FrontController if (class_exists('Piwik\\Profiler')) { Profiler::displayDbProfileReport(); Profiler::printQueryCount(); - Piwik::log(Zend_Registry::get('timer')); + Piwik::log(Registry::get('timer')); } } catch (Exception $e) { } @@ -224,7 +224,7 @@ class FrontController $initialized = true; try { - \Zend_Registry::set('timer', new Timer); + Registry::set('timer', new Timer); $directoriesToCheck = array( '/tmp/', @@ -283,7 +283,7 @@ class FrontController Piwik_PostEvent('FrontController.initAuthenticationObject'); try { - $authAdapter = \Zend_Registry::get('auth'); + $authAdapter = Registry::get('auth'); } catch (Exception $e) { throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated? <br />You can activate the plugin by adding:<br /> diff --git a/core/Log.php b/core/Log.php index f3e566c12d..8b9dc0d779 100644 --- a/core/Log.php +++ b/core/Log.php @@ -467,4 +467,4 @@ class Log } return false; } -}
\ No newline at end of file +} diff --git a/core/Piwik.php b/core/Piwik.php index 4977cb1dad..4223833534 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -16,10 +16,10 @@ use Piwik\Db\Schema; use Piwik\Db; use Piwik\Plugin; use Piwik\Plugins\UsersManager\API; +use Piwik\Registry; use Piwik\Session; use Piwik\Tracker; use Piwik\View; -use Zend_Registry; /** * @see core/Translate.php @@ -445,7 +445,7 @@ class Piwik */ static public function getLoginPluginName() { - return \Zend_Registry::get('auth')->getName(); + return Registry::get('auth')->getName(); } /** diff --git a/core/Registry.php b/core/Registry.php new file mode 100644 index 0000000000..8081989b7c --- /dev/null +++ b/core/Registry.php @@ -0,0 +1,64 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ +namespace Piwik; + +/** + * Registry class. + * + * @package Piwik + */ +class Registry +{ + private static $instance; + private $data; + + private function __construct() { + $this->data = array(); + } + + public static function getInstance() { + if(self::$instance == null) { + self::$instance = new Registry(); + } + return self::$instance; + } + + public static function isRegistered($key) { + return self::getInstance()->hasKey($key); + } + + public static function get($key) { + return self::getInstance()->getKey($key); + } + + public static function set($key, $value) { + self::getInstance()->setKey($key, $value); + } + + public static function unsetInstance() { + self::$instance = null; + } + + public function setKey($key, $value) { + $this->data[$key] = $value; + } + + public function getKey($key) { + if(!$this->hasKey($key)) { + throw new \Exception(sprintf("Key '%s' doesn't exist in Registry", $key)); + } + return $this->data[$key]; + } + + public function hasKey($key) { + return array_key_exists($key, $this->data); + } +} diff --git a/core/Tracker.php b/core/Tracker.php index ad1f40e736..3a4c6bd113 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -18,7 +18,6 @@ use Piwik\Tracker\Db\Pdo\Mysql; use Piwik\Tracker\Request; use Piwik\Tracker\Visit; use Piwik\Tracker\VisitInterface; -use Zend_Registry; /** * Class used by the logging script piwik.php called by the javascript tag. diff --git a/core/View.php b/core/View.php index 2898658592..8256f96ad5 100644 --- a/core/View.php +++ b/core/View.php @@ -11,11 +11,11 @@ namespace Piwik; use Exception; +use Piwik\Registry; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API as APIUsersManager; use Piwik\View\ViewInterface; use Twig_Environment; -use Zend_Registry; /** * Transition for pre-Piwik 0.4.4 @@ -148,7 +148,7 @@ class View implements ViewInterface } try { - $this->totalTimeGeneration = \Zend_Registry::get('timer')->getTime(); + $this->totalTimeGeneration = Registry::get('timer')->getTime(); $this->totalNumberOfQueries = Profiler::getQueryCount(); } catch (Exception $e) { $this->totalNumberOfQueries = 0; diff --git a/plugins/LanguagesManager/Controller.php b/plugins/LanguagesManager/Controller.php index 2f8ea5dd54..7d716013df 100644 --- a/plugins/LanguagesManager/Controller.php +++ b/plugins/LanguagesManager/Controller.php @@ -15,7 +15,6 @@ use Piwik\Common; use Piwik\DbHelper; use Piwik\Piwik; use Piwik\Url; -use Zend_Registry; /** * @package LanguagesManager @@ -35,7 +34,7 @@ class Controller extends \Piwik\Controller $this->checkTokenInUrl(); } LanguagesManager::setLanguageForSession($language); - if (Zend_Registry::isRegistered('access')) { + if (\Piwik\Registry::isRegistered('access')) { $currentUser = Piwik::getCurrentUserLogin(); if ($currentUser && $currentUser !== 'anonymous') { API::getInstance()->setLanguageForUser($currentUser, $language); diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php index 5d89c58b68..44695a20c1 100644 --- a/plugins/Login/Login.php +++ b/plugins/Login/Login.php @@ -58,8 +58,8 @@ class Login extends \Piwik\Plugin */ public function ApiRequestAuthenticate($tokenAuth) { - \Zend_Registry::get('auth')->setLogin($login = null); - \Zend_Registry::get('auth')->setTokenAuth($tokenAuth); + \Piwik\Registry::get('auth')->setLogin($login = null); + \Piwik\Registry::get('auth')->setTokenAuth($tokenAuth); } /** @@ -69,7 +69,7 @@ class Login extends \Piwik\Plugin function initAuthenticationObject($allowCookieAuthentication = false) { $auth = new Auth(); - \Zend_Registry::set('auth', $auth); + \Piwik\Registry::set('auth', $auth); $action = Piwik::getAction(); if (Piwik::getModule() === 'API' @@ -107,7 +107,7 @@ class Login extends \Piwik\Plugin $tokenAuth = API::getInstance()->getTokenAuth($login, $md5Password); - $auth = \Zend_Registry::get('auth'); + $auth = \Piwik\Registry::get('auth'); $auth->setLogin($login); $auth->setTokenAuth($tokenAuth); $authResult = $auth->authenticate(); diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php index 953ad14e21..42d4c97067 100644 --- a/plugins/Overlay/API.php +++ b/plugins/Overlay/API.php @@ -121,7 +121,7 @@ class API Piwik_PostEvent('FrontController.initAuthenticationObject', array(&$notification, $allowCookieAuthentication = true)); - $auth = \Zend_Registry::get('auth'); + $auth = \Piwik\Registry::get('auth'); $success = Access::getInstance()->reloadAccess($auth); if (!$success) { diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 57d69fc962..9a03823134 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -46,7 +46,7 @@ class API * Example of how you would overwrite the UsersManager_API with your own class: * Call the following in your plugin __construct() for example: * - * \Zend_Registry::set('UsersManager_API',Piwik_MyCustomUsersManager_API::getInstance()); + * Registry::set('UsersManager_API',Piwik_MyCustomUsersManager_API::getInstance()); * * @throws Exception * @return \Piwik\Plugins\UsersManager\API @@ -54,7 +54,7 @@ class API static public function getInstance() { try { - $instance = \Zend_Registry::get('UsersManager_API'); + $instance = \Piwik\Registry::get('UsersManager_API'); if (!($instance instanceof API)) { // Exception is caught below and corrected throw new Exception('UsersManager_API must inherit API'); @@ -62,7 +62,7 @@ class API self::$instance = $instance; } catch (Exception $e) { self::$instance = new self; - \Zend_Registry::set('UsersManager_API', self::$instance); + \Piwik\Registry::set('UsersManager_API', self::$instance); } return self::$instance; } diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php index c91651ad97..584479dc85 100644 --- a/tests/PHPUnit/DatabaseTestCase.php +++ b/tests/PHPUnit/DatabaseTestCase.php @@ -77,7 +77,7 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase Cache::deleteTrackerCache(); Config::getInstance()->clear(); ArchiveTableCreator::clear(); - \Zend_Registry::_unsetInstance(); + \Piwik\Registry::unsetInstance(); } } diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 4294f3109b..7ff9e93c5a 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -240,7 +240,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase Config::getInstance()->clear(); ArchiveTableCreator::clear(); \Piwik\Plugins\PDFReports\API::$cache = array(); - \Zend_Registry::_unsetInstance(); + \Piwik\Registry::unsetInstance(); $_GET = $_REQUEST = array(); Translate::getInstance()->unloadEnglishTranslation(); |