1 | <?php |
||
20 | class Container |
||
21 | { |
||
22 | /** |
||
23 | * Services defined for this container. |
||
24 | * |
||
25 | * @var Definition[] |
||
26 | */ |
||
27 | private $definitions; |
||
28 | |||
29 | /** |
||
30 | * Cached instances of services in this container. |
||
31 | * |
||
32 | * @var object[] |
||
33 | */ |
||
34 | private $instances; |
||
35 | |||
36 | /** |
||
37 | * @var Bag |
||
38 | */ |
||
39 | private $parameterBag; |
||
40 | |||
41 | /** |
||
42 | * Create a new Container instance. |
||
43 | */ |
||
44 | public function __construct() |
||
48 | |||
49 | /** |
||
50 | * Define a service within the container, optionally providing a pre-existing instance of the service. |
||
51 | * |
||
52 | * @param Definition $definition |
||
53 | * @param mixed|null $instance |
||
54 | */ |
||
55 | public function define(Definition $definition, $instance = null) |
||
63 | |||
64 | /** |
||
65 | * Helper method to define a service by name and instance. |
||
66 | * |
||
67 | * @param string $serviceName |
||
68 | * @param mixed $instance |
||
69 | */ |
||
70 | public function defineInstance($serviceName, $instance) |
||
78 | |||
79 | /** |
||
80 | * Undefine a service by name. |
||
81 | * |
||
82 | * @param $serviceName |
||
83 | */ |
||
84 | public function undefine($serviceName) |
||
90 | |||
91 | /** |
||
92 | * Retrieve a service from the container. |
||
93 | * |
||
94 | * @param $serviceName |
||
95 | * @return mixed |
||
96 | * @throws \RuntimeException |
||
97 | */ |
||
98 | public function get($serviceName) |
||
122 | |||
123 | /** |
||
124 | * Get a parameter stored in the container. |
||
125 | * |
||
126 | * @param string $name The parameter name |
||
127 | * @return mixed|null |
||
128 | */ |
||
129 | public function getParameter($name) |
||
133 | |||
134 | /** |
||
135 | * Save a parameter into the container. |
||
136 | * |
||
137 | * @param string $name The parameter name |
||
138 | * @param mixed $value |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function setParameter($name, $value) |
||
145 | |||
146 | /** |
||
147 | * Checks if a parameter exists. |
||
148 | * |
||
149 | * @param string $name The parameter name |
||
150 | * @return bool The presence of the named parameter in the container |
||
151 | */ |
||
152 | public function hasParameter($name) |
||
156 | |||
157 | /** |
||
158 | * Return the bag used for storing parameters in the container. |
||
159 | * |
||
160 | * @return Bag |
||
161 | */ |
||
162 | public function getParameterBag() |
||
166 | |||
167 | /** |
||
168 | * Check if $serviceName is defined inside this container. |
||
169 | * |
||
170 | * @param $serviceName |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function isDefined($serviceName) |
||
177 | |||
178 | /** |
||
179 | * Check if $serviceName is defined and instantiated inside this container. |
||
180 | * |
||
181 | * @param $serviceName |
||
182 | * @return bool |
||
183 | */ |
||
184 | public function isInstantiated($serviceName) |
||
188 | |||
189 | /** |
||
190 | * @return Definition[] |
||
191 | */ |
||
192 | public function getDefinitions() |
||
196 | |||
197 | /** |
||
198 | * Build and return a new instance of a service from a Definition instance. |
||
199 | * |
||
200 | * @param Definition $definition |
||
201 | * @return object |
||
202 | */ |
||
203 | private function buildInstance(Definition $definition) |
||
235 | |||
236 | /** |
||
237 | * Resolve an array of arguments into their actual instances or parameter values. |
||
238 | * |
||
239 | * @param array $arguments |
||
240 | * @return array |
||
241 | */ |
||
242 | private function resolveArguments(array $arguments) |
||
264 | |||
265 | } |
||
266 |