1 | <?php |
||
13 | class Container implements ContainerInterface, ArrayAccess |
||
|
|||
14 | { |
||
15 | /** |
||
16 | * @var array 服务定义 |
||
17 | */ |
||
18 | protected $definitions = []; |
||
19 | /** |
||
20 | * @var array 已实例化的服务 |
||
21 | */ |
||
22 | protected $instances = []; |
||
23 | |||
24 | /** |
||
25 | * 添加服务 |
||
26 | * |
||
27 | * @param string $id 服务唯一标识 |
||
28 | * @param Closure $callback |
||
29 | */ |
||
30 | public function set($id, Closure $callback) |
||
36 | |||
37 | /** |
||
38 | * 查找服务是否存在 |
||
39 | * |
||
40 | * @param string $id 服务唯一标识 |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function has($id) |
||
47 | |||
48 | /** |
||
49 | * 获取服务 |
||
50 | * |
||
51 | * @param string $id 服务唯一标识 |
||
52 | * @return mixed |
||
53 | * @throws ServiceNotFoundException |
||
54 | */ |
||
55 | public function get($id) |
||
74 | |||
75 | public function __get($name) |
||
79 | |||
80 | public function __set($name, $value) |
||
84 | |||
85 | public function offsetExists($offset) |
||
89 | |||
90 | public function offsetGet($offset) |
||
94 | |||
95 | public function offsetSet($offset, $value) |
||
99 | |||
100 | public function offsetUnset($offset) |
||
105 | } |