mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-13 10:24:00 +02:00
update deps & install rector
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace DesignPatterns\Structural\Registry;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
abstract class Registry
|
||||
{
|
||||
const LOGGER = 'logger';
|
||||
@@ -12,19 +14,16 @@ abstract class Registry
|
||||
*
|
||||
* @var Service[]
|
||||
*/
|
||||
private static $services = [];
|
||||
private static array $services = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $allowedKeys = [
|
||||
private static array $allowedKeys = [
|
||||
self::LOGGER,
|
||||
];
|
||||
|
||||
public static function set(string $key, Service $value)
|
||||
{
|
||||
if (!in_array($key, self::$allowedKeys)) {
|
||||
throw new \InvalidArgumentException('Invalid key given');
|
||||
throw new InvalidArgumentException('Invalid key given');
|
||||
}
|
||||
|
||||
self::$services[$key] = $value;
|
||||
@@ -33,7 +32,7 @@ abstract class Registry
|
||||
public static function get(string $key): Service
|
||||
{
|
||||
if (!in_array($key, self::$allowedKeys) || !isset(self::$services[$key])) {
|
||||
throw new \InvalidArgumentException('Invalid key given');
|
||||
throw new InvalidArgumentException('Invalid key given');
|
||||
}
|
||||
|
||||
return self::$services[$key];
|
||||
|
Reference in New Issue
Block a user