mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 15:06:31 +02:00
add psalm and travis check
This commit is contained in:
@@ -5,18 +5,17 @@ namespace DesignPatterns\More\ServiceLocator;
|
||||
class ServiceLocator
|
||||
{
|
||||
/**
|
||||
* @var array|Service[]
|
||||
* @var string[][]
|
||||
*/
|
||||
private $services = [];
|
||||
|
||||
/**
|
||||
* @var array|Service[]
|
||||
* @var Service[]
|
||||
*/
|
||||
private $instantiated = [];
|
||||
|
||||
public function addInstance(string $class, Service $service)
|
||||
{
|
||||
$this->services[$class] = $service;
|
||||
$this->instantiated[$class] = $service;
|
||||
}
|
||||
|
||||
@@ -55,6 +54,10 @@ class ServiceLocator
|
||||
throw new \OutOfRangeException('Too many arguments given');
|
||||
}
|
||||
|
||||
if (!$object instanceof Service) {
|
||||
throw new \InvalidArgumentException('Could not register service: is no instance of Service');
|
||||
}
|
||||
|
||||
$this->instantiated[$class] = $object;
|
||||
|
||||
return $object;
|
||||
|
Reference in New Issue
Block a user