diff --git a/src/Genie.php b/src/Genie.php index d949dc3..98a8b42 100644 --- a/src/Genie.php +++ b/src/Genie.php @@ -91,6 +91,20 @@ public function construct(string $target, ...$pool) 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($target, ...$pool): iterable + { + return $this->resolveArguments($target, ...$pool); + } + /** * Provide services without directly exposing them. * Returns a fellow invoker with the requested services provisioned. diff --git a/tests/GenieCoreTest.php b/tests/GenieCoreTest.php index 6c158be..8667596 100644 --- a/tests/GenieCoreTest.php +++ b/tests/GenieCoreTest.php @@ -15,6 +15,19 @@ class GenieCoreTest extends TestCase { use WithStuff; + public function testGenieProvisionsCallArguments() + { + $g = new Genie($c = new Sleeve([ + Frog::class => new Frog(), + ])); + $f1 = function (Frog $frog, int $answer) { + }; + $args = $g->provision($f1, 42); + $this->assertSame($c[Frog::class], $args[0]); + $this->assertSame(42, $args[1]); + $this->assertCount(2, $args); + } + public function testGenieUsesACoreProperlyPassingArguments() { $passed = []; diff --git a/tests/GenieProvisioningTest.php b/tests/GenieProvisioningTest.php index bf65daa..3837a33 100644 --- a/tests/GenieProvisioningTest.php +++ b/tests/GenieProvisioningTest.php @@ -26,7 +26,7 @@ public function testProvideReturnsASimpleton() $this->assertTrue($wg->provide() instanceof Simpleton); } - public function testProvisioning() + public function testGenieProvidesServices() { $sleeve = ContainerProvider::createContainer(); $wg = new Genie($sleeve);