Simplify service locator get method

This commit is contained in:
Alexander Schranz
2022-06-19 22:29:06 +02:00
parent 8d6d00d356
commit 230b32c9d7

View File

@@ -40,24 +40,7 @@ class ServiceLocator
return $this->instantiated[$class];
}
$args = $this->services[$class];
switch (count($args)) {
case 0:
$object = new $class();
break;
case 1:
$object = new $class($args[0]);
break;
case 2:
$object = new $class($args[0], $args[1]);
break;
case 3:
$object = new $class($args[0], $args[1], $args[2]);
break;
default:
throw new OutOfRangeException('Too many arguments given');
}
$object = new $class(...$this->services[$class]);
if (!$object instanceof Service) {
throw new InvalidArgumentException('Could not register service: is no instance of Service');