-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceContainer.php
More file actions
30 lines (24 loc) · 910 Bytes
/
ServiceContainer.php
File metadata and controls
30 lines (24 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace Hiro;
class ServiceContainer extends DIContainer
{
public function __construct($config) {
foreach($config as $name => $configItem) {
$this->$name = $this->asShared(function($c) use($name, $configItem) {
$class = new \ReflectionClass($configItem['class']);
$arguments = [];
if(isset($configItem['arguments'])) {
foreach($configItem['arguments'] as $arg) {
$arguments[] = $arg;
}
}
if(isset($configItem['calls'])) {
foreach($configItem['calls'] as $call) {
$arguments[] = $c->$call;
}
}
return $class->newInstanceArgs($arguments);
});
}
}
}