Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterGdot committed Jul 25, 2024
1 parent 69e7b50 commit e1cd2a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
}
],
"minimum-stability": "dev",
"require": {}
"require": {
"php" : ">=8.2"
}
}
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions src/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -129,14 +133,15 @@ public function resolve(): ?object
$this->object = $this->implementation;
}

$this->isResolving = false;
return $this->object;
} catch (Exception $ex) {
if ($this->fireExceptions) {
throw $ex;
} else {
return null;
}
} finally {
$this->isResolving = false;
}
}
}
6 changes: 5 additions & 1 deletion src/Ioc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e1cd2a5

Please sign in to comment.