Total Complexity | 5 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | final class Services |
||
8 | { |
||
9 | private $aliases = []; |
||
10 | private $locator; |
||
11 | |||
12 | /** |
||
13 | * @param array $aliases |
||
14 | * @param ServiceLocator $locator |
||
15 | */ |
||
16 | public function __construct(array $aliases, ServiceLocator $locator) |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param string $alias |
||
24 | * |
||
25 | * @return object |
||
26 | * |
||
27 | * @throws \InvalidArgumentException |
||
28 | */ |
||
29 | public function get($alias) |
||
30 | { |
||
31 | if (!isset($this->aliases[$alias])) { |
||
32 | throw new \InvalidArgumentException(sprintf('Service with alias "%s" is not registered.', $alias)); |
||
33 | } |
||
34 | |||
35 | $serviceId = $this->aliases[$alias]; |
||
36 | |||
37 | return $this->locator->get($serviceId); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string $method |
||
42 | * @param array $args |
||
43 | * |
||
44 | * @return object |
||
45 | * |
||
46 | * @throws \BadMethodCallException |
||
47 | */ |
||
48 | public function __call($method, array $args) |
||
58 | } |
||
59 | } |
||
60 |