Skip to content

Commit

Permalink
Implement injection into provide method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Vegner committed Jan 18, 2018
1 parent 0ef68e1 commit 14c5ca6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/InjectionReceiverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function getServiceName(): string {
return 'service';
}

public function provide($param) {
public function provide(string $param = '') {
return (object)[
'param' => $param,
];
Expand Down

0 comments on commit 14c5ca6

Please sign in to comment.