mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 18:50:11 +02:00
Merge pull request #483 from alexander-schranz/enhancement/simplify-service-locator-get
Simplify service locator get method
This commit is contained in:
@@ -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');
|
||||
|
Reference in New Issue
Block a user