diff --git a/src/Container.php b/src/Container.php index 430c174..8e021ad 100644 --- a/src/Container.php +++ b/src/Container.php @@ -29,7 +29,7 @@ public function __construct(array $config = [], $selfName = '') { public function connect(ProviderInterface $provider) { $this->register($provider->getServiceName(), function () use ($provider) { $this->injectRecursive($provider); - return $provider->provide(); + return $this->inject([$provider, 'provide']); }); } @@ -90,7 +90,7 @@ public function get($name) { private function injectRecursive($consumer) { if (is_callable($consumer)) { - $parameters = $this->getParameterValues(new \ReflectionFunction($consumer)); + $parameters = $this->getParameterValues(new \ReflectionFunction(\Closure::fromCallable($consumer))); return $consumer(...$parameters); } else { $consumer = $this->injectDeclarer($consumer); diff --git a/tests/InjectionReceiverProvider.php b/tests/InjectionReceiverProvider.php index 280d467..e266886 100644 --- a/tests/InjectionReceiverProvider.php +++ b/tests/InjectionReceiverProvider.php @@ -8,7 +8,7 @@ public function getServiceName(): string { return 'service'; } - public function provide($param) { + public function provide(string $param = '') { return (object)[ 'param' => $param, ];