From 14c5ca67be8a1d3084bf45757bbaff480a8cc1a7 Mon Sep 17 00:00:00 2001 From: Ivan Vegner Date: Thu, 18 Jan 2018 12:11:03 +0300 Subject: [PATCH] Implement injection into provide method --- src/Container.php | 4 ++-- tests/InjectionReceiverProvider.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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, ];