blob: ad1412bb54fe2de4dc0ea06e2b7e3ef5f068b657 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<?php
namespace SMW\Tests\Utils;
use InvalidArgumentException;
/**
* @license GNU GPL v2+
* @since 1.9.1
*
* @author mwjames
*/
class GlobalsProvider {
/**
* @var GlobalsProvider
*/
private static $instance = null;
/**
* @var array
*/
private $container = null;
/**
* @since 1.9.1
*
* @return GlobalsProvider
*/
public static function getInstance() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance->setContainer( $GLOBALS );
}
/**
* @since 1.9.1
*/
public static function clear() {
self::$instance = null;
}
/**
* @since 1.9.1
*
* @param string $key
*
* @return mixed
*/
public function get( $key ) {
if ( is_string( $key ) && $this->contains( $key ) ) {
return $this->lookup( $key );
}
throw new InvalidArgumentException( 'Configuration key is unkown' );
}
/**
* @since 2.0
*
* @param string $key
* @param mixed $value
*/
public function set( $key, $value ) {
if ( is_string( $key ) ) {
$this->container[$key] = $value;
}
return $this;
}
protected function setContainer( $container ) {
$this->container = $container;
return $this;
}
protected function contains( $key ) {
return isset( $this->container[$key] ) || array_key_exists( $key, $this->container );
}
protected function lookup( $key ) {
return $this->container[$key];
}
}
|