1 | <?php |
||
26 | class Services implements ArrayAccess |
||
27 | { |
||
28 | /** @type Services $default default service container */ |
||
29 | public static $default = null; |
||
30 | |||
31 | /** @type array $services shared service objects */ |
||
32 | protected $services = []; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Returns the instance of default service container |
||
37 | * |
||
38 | * @return Services default service container |
||
39 | */ |
||
40 | public static function getCurrent() |
||
48 | |||
49 | /** |
||
50 | * Sets a service definition |
||
51 | * |
||
52 | * @param string $uId name of the service |
||
53 | * @param mixed $uValue any value |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | public function offsetSet($uId, $uValue) |
||
61 | |||
62 | /** |
||
63 | * Sets a factory function in order to generate service instances |
||
64 | * |
||
65 | * @param string $uName name of the service |
||
66 | * @param callable $uCallback callback generates service instances |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | public function setFactory($uName, $uCallback) |
||
74 | |||
75 | /** |
||
76 | * Sets a factory function in order to generate service instances |
||
77 | * |
||
78 | * @param string $uName name of the service |
||
79 | * @param callable $uCallback callback generates service instances |
||
80 | * |
||
81 | * @throws InvalidArgumentException if the service is not defined |
||
82 | * @return void |
||
83 | */ |
||
84 | public function decorate($uName, $uCallback) |
||
104 | |||
105 | /** |
||
106 | * Gets the service instance or invokes factory callback if the service is defined |
||
107 | * |
||
108 | * @param string $uId name of the service |
||
109 | * |
||
110 | * @throws InvalidArgumentException if the service is not defined |
||
111 | * @return mixed the service instance |
||
112 | */ |
||
113 | public function offsetGet($uId) |
||
128 | |||
129 | /** |
||
130 | * Checks if service is defined |
||
131 | * |
||
132 | * @param string $uId name of the service |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function offsetExists($uId) |
||
140 | |||
141 | /** |
||
142 | * Unsets a service |
||
143 | * |
||
144 | * @param string $uId name of the service |
||
145 | * |
||
146 | * @return void |
||
147 | */ |
||
148 | public function offsetUnset($uId) |
||
152 | } |
||
153 |