Skip to content

Commit d93f4e8

Browse files
author
Dominik Liebler
authored
Merge pull request DesignPatternsPHP#483 from alexander-schranz/enhancement/simplify-service-locator-get
Simplify service locator get method
2 parents 8d6d00d + 230b32c commit d93f4e8

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

More/ServiceLocator/ServiceLocator.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,7 @@ public function get(string $class): Service
4040
return $this->instantiated[$class];
4141
}
4242

43-
$args = $this->services[$class];
44-
45-
switch (count($args)) {
46-
case 0:
47-
$object = new $class();
48-
break;
49-
case 1:
50-
$object = new $class($args[0]);
51-
break;
52-
case 2:
53-
$object = new $class($args[0], $args[1]);
54-
break;
55-
case 3:
56-
$object = new $class($args[0], $args[1], $args[2]);
57-
break;
58-
default:
59-
throw new OutOfRangeException('Too many arguments given');
60-
}
43+
$object = new $class(...$this->services[$class]);
6144

6245
if (!$object instanceof Service) {
6346
throw new InvalidArgumentException('Could not register service: is no instance of Service');

0 commit comments

Comments
 (0)