From e1cd2a5ccf5ada477d9ba6debbcc6a6c509f1d5b Mon Sep 17 00:00:00 2001 From: Peter Grundmann Date: Thu, 25 Jul 2024 19:33:40 +0200 Subject: [PATCH] fixes --- composer.json | 4 +++- readme.md | 3 ++- src/Binding.php | 9 +++++++-- src/Ioc.php | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 8d9d8ec..252ff31 100644 --- a/composer.json +++ b/composer.json @@ -15,5 +15,7 @@ } ], "minimum-stability": "dev", - "require": {} + "require": { + "php" : ">=8.2" + } } diff --git a/readme.md b/readme.md index d1401f2..6cfe21e 100644 --- a/readme.md +++ b/readme.md @@ -8,10 +8,11 @@ A simple lightweight PHP Inversion of Control (IoC) container with the following - can bind with optional arguments - detect cyclic dependencies during the object creation phase - support for multiple, independent containers +- no external dependencies - easy to use ## Requirements -- php 8.3 or higher +- php 8.2 or higher ## Usage diff --git a/src/Binding.php b/src/Binding.php index ad51cd6..356adef 100644 --- a/src/Binding.php +++ b/src/Binding.php @@ -109,7 +109,11 @@ public function resolve(): ?object } // b) callable => return callable result else if (is_callable($this->implementation)) { - $refl = new \ReflectionFunction($this->implementation); + if (is_array($this->implementation)) { + $refl = new \ReflectionMethod($this->implementation[0], $this->implementation[1]); + } else { + $refl = new \ReflectionFunction($this->implementation); + } $args = ParameterResolver::resolve($this->ioc, $refl->getParameters(), $this->overrides); $this->object = call_user_func_array($this->implementation, $args); } @@ -129,7 +133,6 @@ public function resolve(): ?object $this->object = $this->implementation; } - $this->isResolving = false; return $this->object; } catch (Exception $ex) { if ($this->fireExceptions) { @@ -137,6 +140,8 @@ public function resolve(): ?object } else { return null; } + } finally { + $this->isResolving = false; } } } \ No newline at end of file diff --git a/src/Ioc.php b/src/Ioc.php index 1dbe2b8..260eedf 100644 --- a/src/Ioc.php +++ b/src/Ioc.php @@ -42,7 +42,11 @@ public static function bindSingleton(string $name, string|callable|null|object $ public static function get(string $name): ?object { return static::$default->resolve($name); - } + } + + public static function has(string $name): bool { + return isset(static::$default->bindings[$name]); + } #endregion