blob: 166a48f772d1e31bf342c1e05b5ae43fced95717 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik;
/**
* Registry class.
*
* @method static \Piwik\Registry getInstance()
*/
class Registry extends Singleton
{
private $data;
protected function __construct()
{
$this->data = array();
}
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 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);
}
}
|