Skip to content

Commit

Permalink
Genie::provision()
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Dec 6, 2020
1 parent aa82672 commit d79182b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/Genie.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ public function construct(string $target, ...$pool): mixed
return new $target(...$this->resolveArguments($target, ...$pool));
}

/**
* Inspect the given target and return an iterable list of arguments
* usable for invoking/constructing the target (using argument unpacking, the splat operator).
* Does not invoke/construct the target.
*
* @param callable|string $target
* @param mixed ...$pool
* @return iterable
*/
public function provision(callable|string $target, ...$pool): iterable
{
return $this->resolveArguments($target, ...$pool);
}

/**
* Provide services without directly exposing them.
* Returns a fellow invoker with the requested services provisioned.
Expand Down
23 changes: 9 additions & 14 deletions tests/GenieAttributesShowcaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ public function testEverything()
return func_get_args();
};

$g = new Genie($sleeve);
$args = [
...$this->with($g, function () use ($toCall) {
return $this->resolveArguments(
$toCall,
'not autowired',
null,
'another value',
'these are the remaining arguments',
123,
value: 42,
);
}),
];
$args = (new Genie($sleeve))->provision(
$toCall,
'not autowired',
null,
'another value',
'these are the remaining arguments',
123,
value: 42,
);

$this->assertInstanceOf(Thing::class, $args[0] ?? null);
$this->assertSame($sleeve[Thing::class], $args[0] ?? null);
Expand Down

0 comments on commit d79182b

Please sign in to comment.