1 | <?php |
||
10 | abstract class Container |
||
11 | { |
||
12 | /** |
||
13 | * The current globally available container (if any). |
||
14 | * |
||
15 | * @var static |
||
16 | */ |
||
17 | protected static $instance; |
||
18 | |||
19 | /** |
||
20 | * The container's bound services. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $services = []; |
||
25 | |||
26 | /** |
||
27 | * The container's bucket items |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $bucket = []; |
||
32 | |||
33 | /** |
||
34 | * Set the globally available instance of the container. |
||
35 | * |
||
36 | * @return static |
||
37 | */ |
||
38 | 14 | public static function getInstance() |
|
46 | |||
47 | /** |
||
48 | * Bind a service to the container. |
||
49 | * |
||
50 | * @param string $alias |
||
51 | * @param mixed $concrete |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function bind( $alias, $concrete ) |
||
59 | |||
60 | /** |
||
61 | * Resolve the given type from the container. |
||
62 | * Allow unbound aliases that omit the root namespace |
||
63 | * i.e. 'Controller' translates to 'GeminiLabs\Pollux\Controller' |
||
64 | * |
||
65 | * @param mixed $abstract |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function make( $abstract ) |
||
84 | |||
85 | /** |
||
86 | * Register a shared binding in the container. |
||
87 | * |
||
88 | * @param string $abstract |
||
89 | * @param \Closure|string|null $concrete |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | public function singleton( $abstract, $concrete ) |
||
97 | |||
98 | /** |
||
99 | * Dynamically access container bucket items. |
||
100 | * |
||
101 | * @param string $item |
||
102 | * |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function __get( $item ) |
||
111 | |||
112 | /** |
||
113 | * Dynamically set container bucket items. |
||
114 | * |
||
115 | * @param string $item |
||
116 | * @param mixed $value |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | public function __set( $item, $value ) |
||
124 | |||
125 | /** |
||
126 | * Register a Provider. |
||
127 | * |
||
128 | * @return void |
||
129 | */ |
||
130 | public function register( $provider ) |
||
134 | |||
135 | /** |
||
136 | * Prefix the current namespace to the abstract if absent |
||
137 | * |
||
138 | * @param string $abstract |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | protected function addNamespace( $abstract ) |
||
150 | |||
151 | /** |
||
152 | * Throw an exception that the concrete is not instantiable. |
||
153 | * |
||
154 | * @param string $concrete |
||
155 | * |
||
156 | * @return void |
||
157 | * @throws Exception |
||
158 | */ |
||
159 | protected function notInstantiable( $concrete ) |
||
165 | |||
166 | /** |
||
167 | * Resolve a class based dependency from the container. |
||
168 | * |
||
169 | * @param mixed $concrete |
||
170 | * |
||
171 | * @return mixed |
||
172 | * @throws Exception |
||
173 | */ |
||
174 | protected function resolve( $concrete ) |
||
194 | |||
195 | /** |
||
196 | * Resolve a class based dependency from the container. |
||
197 | * |
||
198 | * @return mixed |
||
199 | * @throws Exception |
||
200 | */ |
||
201 | protected function resolveClass( ReflectionParameter $parameter ) |
||
213 | |||
214 | /** |
||
215 | * Resolve all of the dependencies from the ReflectionParameters. |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | protected function resolveDependencies( array $dependencies ) |
||
232 | } |
||
233 |