diff --git a/src/Contracts/DependencyResolver.php b/src/Contracts/DependencyResolver.php new file mode 100644 index 0000000..7582f3b --- /dev/null +++ b/src/Contracts/DependencyResolver.php @@ -0,0 +1,57 @@ + $bindings + * @return mixed + * + * @throws ClassCannotBeInstantiated + * @throws CannotAutowireDependencyArgument + */ + public function construct(string $className, array $bindings = []): mixed; + + /** + * Call the given callable with its arguments automatically wired using the container state. + * + * @template T + * @param callable():T $callable + * @param array $bindings + * @return T + * + * @throws ArgumentCountError + * @throws CannotAutowireArgument + */ + public function call(callable $callable, array $bindings = []): mixed; +} \ No newline at end of file diff --git a/src/DependencyResolver.php b/src/DependencyResolver.php index 4125d37..9ec9f8b 100644 --- a/src/DependencyResolver.php +++ b/src/DependencyResolver.php @@ -8,13 +8,14 @@ use Psr\Container\ContainerInterface; use Technically\CallableReflection\CallableReflection; use Technically\CallableReflection\Parameters\ParameterReflection; +use Technically\DependencyResolver\Contracts\DependencyResolver as DependencyResolverInterface; use Technically\DependencyResolver\Exceptions\CannotAutowireArgument; use Technically\DependencyResolver\Exceptions\CannotAutowireDependencyArgument; use Technically\DependencyResolver\Exceptions\ClassCannotBeInstantiated; use Technically\DependencyResolver\Exceptions\DependencyResolutionException; use Technically\NullContainer\NullContainer; -final class DependencyResolver +final class DependencyResolver implements DependencyResolverInterface { private ContainerInterface $container; @@ -24,7 +25,7 @@ public function __construct(?ContainerInterface $container = null) } /** - * @param string $className + * @param class-string $className * @return mixed * * @throws InvalidArgumentException If class does not exist. @@ -46,8 +47,8 @@ public function resolve(string $className): mixed } /** - * @param string $className - * @param array $bindings + * @param class-string $className + * @param array $bindings * @return mixed * * @throws ClassCannotBeInstantiated @@ -75,9 +76,10 @@ public function construct(string $className, array $bindings = []): mixed } /** - * @param callable $callable - * @param array $bindings - * @return mixed + * @template T + * @param callable():T $callable + * @param array $bindings + * @return T * * @throws ArgumentCountError * @throws CannotAutowireArgument @@ -93,7 +95,7 @@ public function call(callable $callable, array $bindings = []): mixed /** * @param ParameterReflection[] $parameters - * @param array $bindings + * @param array $bindings * @return array * * @throws CannotAutowireArgument