-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.php
53 lines (43 loc) · 1.39 KB
/
registry.php
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
<?php
namespace Framework {
/**
* The Registry is a Singleton, used to store instance of other “normal” classes.
*/
class Registry {
private static $_instances = array();
private function __construct() {
// do nothing
}
private function __clone() {
// do nothing
}
/**
* Searches the private storage for an instance with a matching key.
* If it finds an instance, it will return it, or default to the value supplied with the $default parameter.
* @param type $key
* @param type $default
* @return type
*/
public static function get($key, $default = null) {
if (isset(self::$_instances[$key])) {
return self::$_instances[$key];
}
return $default;
}
/**
* Used to “store” an instance with a specified key in the registry’s private storage
* @param type $key
* @param type $instance
*/
public static function set($key, $instance = null) {
self::$_instances[$key] = $instance;
}
/**
* Useful for removing an instance at a certain key.
* @param type $key
*/
public static function erase($key) {
unset(self::$_instances[$key]);
}
}
}