diff --git a/composer.json b/composer.json index 8fdf8cc..9d8f6e8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "require": { "php": "^7.4|^8.0|^8.1|^8.2|^8.3", "ext-json": "*", - "psr/container": "^2.0", "symfony/polyfill-php80": "^1.29" }, "autoload": { diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 77184e7..5604d69 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -44,24 +44,34 @@ class Dispatcher /** * This is a container for the dependency injection. * - * @var null|ContainerInterface|(callable(string $classString, array $params): (null|object)) + * @var null|ContainerInterface|(callable(string $classString, array $params): (null|object)) */ protected $containerHandler = null; /** * Sets the dependency injection container handler. * - * @param ContainerInterface|(callable(string $classString, array $params): (null|object)) $containerHandler + * @param ContainerInterface|(callable(string $classString, array $params): (null|object)) $containerHandler * Dependency injection container. + * + * @throws InvalidArgumentException If $containerHandler is not a `callable` or instance of `Psr\Container\ContainerInterface`. */ public function setContainerHandler($containerHandler): void { + $containerInterfaceNS = '\Psr\Container\ContainerInterface'; + if ( - $containerHandler instanceof ContainerInterface + is_a($containerHandler, $containerInterfaceNS) || is_callable($containerHandler) ) { $this->containerHandler = $containerHandler; + + return; } + + throw new InvalidArgumentException( + "\$containerHandler must be of type callable or instance $containerInterfaceNS" + ); } public function setEngine(Engine $engine): void @@ -200,7 +210,7 @@ class Dispatcher * * @param string $name Event name * @param 'before'|'after' $type Filter type. - * @param callable(array &$params, string &$output): (void|false) $callback + * @param callable(array &$params, mixed &$output): (void|false)|callable(mixed &$output): (void|false) $callback * * @return $this */ @@ -430,7 +440,7 @@ class Dispatcher { // PSR-11 if ( - $this->containerHandler instanceof ContainerInterface + is_a($this->containerHandler, '\Psr\Container\ContainerInterface') && $this->containerHandler->has($class) ) { return $this->containerHandler->get($class); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9fa597c..e69de29 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,6 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Parameter \\#2 \\$callback of method flight\\\\core\\\\Dispatcher\\:\\:set\\(\\) expects Closure\\(\\)\\: mixed, array\\{\\$this\\(flight\\\\Engine\\), literal\\-string&non\\-falsy\\-string\\} given\\.$#" - count: 1 - path: flight/Engine.php