1 | <?php |
||
12 | class Di implements DiInterface |
||
13 | { |
||
14 | private $elements; // a cache of instantiated elements |
||
15 | private $elementMap; // the map between keys and their elements |
||
16 | |||
17 | private static $instance; // a static instance of this class for static use |
||
18 | |||
19 | /** |
||
20 | * Constructor for the class. |
||
21 | * @param array $elementMap An optional initial set of elements to use. |
||
22 | */ |
||
23 | 61 | public function __construct($elementMap = array()) |
|
28 | |||
29 | /** |
||
30 | * Returns the element associated with the specified key. |
||
31 | * @param string $element The key for the element. |
||
32 | * @param boolean $useCache An optional flag for whether we can use the |
||
33 | * cached version of the element (defaults to true). |
||
34 | * @return Returns the associated element. |
||
35 | * @throws \Exception Throws an exception if no element is registered for |
||
36 | * the given key. |
||
37 | */ |
||
38 | 34 | public function get($element, $useCache = true) |
|
61 | |||
62 | /** |
||
63 | * Assigns a specific element to the given key. This method will override |
||
64 | * any previously assigned element for the given key. |
||
65 | * @param string $key The key for the specified element. |
||
66 | * @param mixed $element The specified element. This can be an instance of the |
||
67 | * element or a callback to be invoked. |
||
68 | * @return Returns $this. |
||
69 | */ |
||
70 | 25 | public function set($key, $element) |
|
77 | |||
78 | /** |
||
79 | * Returns whether or not a given element has been registered. |
||
80 | * @param string $element The key for the element. |
||
81 | * @return Returns true if the element is registered and false otherwise. |
||
82 | */ |
||
83 | 2 | public function hasElement($element) |
|
87 | |||
88 | /** |
||
89 | * Returns an array of all registered keys. |
||
90 | * @return An array of all registered keys. |
||
91 | */ |
||
92 | 3 | public function allRegisteredElements() |
|
96 | |||
97 | /** |
||
98 | * Returns the current default DI instance. |
||
99 | * @return Di The current default DI instance. |
||
100 | */ |
||
101 | 19 | public static function getDefault() |
|
109 | |||
110 | /** |
||
111 | * Sets the current default DI instance.. |
||
112 | * @param DiInterface $instance An instance of DI. |
||
113 | * @return Di Returns the new default DI instance. |
||
114 | */ |
||
115 | 11 | public static function setDefault(DiInterface $instance) |
|
120 | |||
121 | /** |
||
122 | * Clears the current default DI instance. |
||
123 | */ |
||
124 | 1 | public static function clearDefault() |
|
128 | } |
||
129 |