diff options
author | Fabian Becker <fabian.becker@uni-tuebingen.de> | 2013-09-29 19:15:14 +0400 |
---|---|---|
committer | Fabian Becker <fabian.becker@uni-tuebingen.de> | 2013-09-29 19:15:14 +0400 |
commit | 05f76a5826e710929ebc558e846847056222e4fb (patch) | |
tree | 297f2266c8f09bf91089a95907315bdce0c5e1b3 /core/Registry.php | |
parent | cbedab1a2c2a47afbbcdd2909d2036ff2f2b62c1 (diff) |
Add implementation of simple Registry (removing Zend_* dependency)
Diffstat (limited to 'core/Registry.php')
-rw-r--r-- | core/Registry.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/core/Registry.php b/core/Registry.php new file mode 100644 index 0000000000..e2fa0278cb --- /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)) { + return null; + } + return $this->data[$key]; + } + + public function hasKey($key) { + return array_key_exists($key, $this->data); + } +} |