@@ 242-309 (lines=68) @@ | ||
239 | require_once $file; |
|
240 | } |
|
241 | ||
242 | if (isset($definition['factory'])) { |
|
243 | $factory = $definition['factory']; |
|
244 | if (is_array($factory)) { |
|
245 | $factory = $this->resolveServicesAndParameters(array($factory[0], $factory[1])); |
|
246 | } |
|
247 | elseif (!is_string($factory)) { |
|
248 | throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory', $id)); |
|
249 | } |
|
250 | ||
251 | $service = call_user_func_array($factory, $arguments); |
|
252 | } |
|
253 | else { |
|
254 | $class = $this->frozen ? $definition['class'] : current($this->resolveServicesAndParameters(array($definition['class']))); |
|
255 | $length = isset($definition['arguments_count']) ? $definition['arguments_count'] : count($arguments); |
|
256 | ||
257 | // Optimize class instantiation for services with up to 10 parameters as |
|
258 | // ReflectionClass is noticeably slow. |
|
259 | switch ($length) { |
|
260 | case 0: |
|
261 | $service = new $class(); |
|
262 | break; |
|
263 | ||
264 | case 1: |
|
265 | $service = new $class($arguments[0]); |
|
266 | break; |
|
267 | ||
268 | case 2: |
|
269 | $service = new $class($arguments[0], $arguments[1]); |
|
270 | break; |
|
271 | ||
272 | case 3: |
|
273 | $service = new $class($arguments[0], $arguments[1], $arguments[2]); |
|
274 | break; |
|
275 | ||
276 | case 4: |
|
277 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3]); |
|
278 | break; |
|
279 | ||
280 | case 5: |
|
281 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); |
|
282 | break; |
|
283 | ||
284 | case 6: |
|
285 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]); |
|
286 | break; |
|
287 | ||
288 | case 7: |
|
289 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]); |
|
290 | break; |
|
291 | ||
292 | case 8: |
|
293 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]); |
|
294 | break; |
|
295 | ||
296 | case 9: |
|
297 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]); |
|
298 | break; |
|
299 | ||
300 | case 10: |
|
301 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9]); |
|
302 | break; |
|
303 | ||
304 | default: |
|
305 | $r = new \ReflectionClass($class); |
|
306 | $service = $r->newInstanceArgs($arguments); |
|
307 | break; |
|
308 | } |
|
309 | } |
|
310 | ||
311 | // Share the service if it is public. |
|
312 | if (!isset($definition['public']) || $definition['public'] !== FALSE) { |
@@ 74-141 (lines=68) @@ | ||
71 | require_once $file; |
|
72 | } |
|
73 | ||
74 | if (isset($definition['factory'])) { |
|
75 | $factory = $definition['factory']; |
|
76 | if (is_array($factory)) { |
|
77 | $factory = $this->resolveServicesAndParameters(array($factory[0], $factory[1])); |
|
78 | } |
|
79 | elseif (!is_string($factory)) { |
|
80 | throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory', $id)); |
|
81 | } |
|
82 | ||
83 | $service = call_user_func_array($factory, $arguments); |
|
84 | } |
|
85 | else { |
|
86 | $class = $this->frozen ? $definition['class'] : current($this->resolveServicesAndParameters(array($definition['class']))); |
|
87 | $length = isset($definition['arguments_count']) ? $definition['arguments_count'] : count($arguments); |
|
88 | ||
89 | // Optimize class instantiation for services with up to 10 parameters as |
|
90 | // reflection is noticeably slow. |
|
91 | switch ($length) { |
|
92 | case 0: |
|
93 | $service = new $class(); |
|
94 | break; |
|
95 | ||
96 | case 1: |
|
97 | $service = new $class($arguments[0]); |
|
98 | break; |
|
99 | ||
100 | case 2: |
|
101 | $service = new $class($arguments[0], $arguments[1]); |
|
102 | break; |
|
103 | ||
104 | case 3: |
|
105 | $service = new $class($arguments[0], $arguments[1], $arguments[2]); |
|
106 | break; |
|
107 | ||
108 | case 4: |
|
109 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3]); |
|
110 | break; |
|
111 | ||
112 | case 5: |
|
113 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); |
|
114 | break; |
|
115 | ||
116 | case 6: |
|
117 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]); |
|
118 | break; |
|
119 | ||
120 | case 7: |
|
121 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]); |
|
122 | break; |
|
123 | ||
124 | case 8: |
|
125 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]); |
|
126 | break; |
|
127 | ||
128 | case 9: |
|
129 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]); |
|
130 | break; |
|
131 | ||
132 | case 10: |
|
133 | $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9]); |
|
134 | break; |
|
135 | ||
136 | default: |
|
137 | $r = new \ReflectionClass($class); |
|
138 | $service = $r->newInstanceArgs($arguments); |
|
139 | break; |
|
140 | } |
|
141 | } |
|
142 | ||
143 | // Share the service if it is public. |
|
144 | if (!isset($definition['public']) || $definition['public'] !== FALSE) { |