From 9700f7d9b5307f2d0ba65815ef46b17bb36ce346 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 18 May 2023 22:04:19 +0200 Subject: [PATCH] change signature to resolve(callable) --- src/Container/Container.php | 9 +++++---- src/Container/ContainerInterface.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Container/Container.php b/src/Container/Container.php index 3a684b4..e786a2a 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -90,19 +90,20 @@ public function get(string $id): mixed return $this->createInstance($id); } - public function resolve(Closure $closure): mixed + public function resolve(callable $callable): mixed { - $reflectionFn = new ReflectionFunction($closure); + $callable = Closure::fromCallable($callable); + $reflectionFn = new ReflectionFunction($callable); $callableKey = md5(serialize($reflectionFn->__toString())); if (!isset($this->cachedDependencies[$callableKey])) { $this->cachedDependencies[$callableKey] = $this ->getDependencyResolver() - ->resolveDependencies($closure); + ->resolveDependencies($callable); } /** @psalm-suppress MixedMethodCall */ - return $closure(...$this->cachedDependencies[$callableKey]); + return $callable(...$this->cachedDependencies[$callableKey]); } public function factory(Closure $instance): Closure diff --git a/src/Container/ContainerInterface.php b/src/Container/ContainerInterface.php index dab0ce9..5483056 100644 --- a/src/Container/ContainerInterface.php +++ b/src/Container/ContainerInterface.php @@ -18,7 +18,7 @@ public function get(string $id): mixed; /** * Resolve the closure loading automatically all arguments based on current bindings. */ - public function resolve(Closure $closure): mixed; + public function resolve(callable $callable): mixed; /** * Check if an instance exists.