ellipse / resolvable-callable
Resolvable callable factory allowing to execute callables using a Psr-11 container
1.0.4
2018-02-23 09:56 UTC
Requires
- php: >=7.0
- ellipse/resolvable-value: ^1.0
- psr/container: ^1.0
Requires (Dev)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
README
This package provides a resolvable callable factory allowing to execute callables using a Psr-11 container.
Require php >= 7.0
Installation composer require ellipse/resolvable-callable
Run tests ./vendor/bin/kahlan
Resolve a callable
This package provides a factory producing instances of Ellipse\Resolvable\ResolvableCallable
from callables. Those resolvable callable values can then be produced by calling the ->value()
method with a Psr-11 container and an array of placeholder values.
<?php namespace App; use Some\Psr11Container; use Ellipse\Resolvable\DefaultResolvableCallableFactory; // The callable to resolve. $callable = function (SomeClass $p1, int $p2 = 0, int $p3, string $p4 = 'p4') { // $p1 is the instance returned by $container->get(SomeClass::class); // $p2 value is 2 // $p3 value is 3 // $p3 value is 'p4' return 'result'; }; // Some Psr-11 container. $container = new Psr11Container; // Resolve the callable. $resolved value is 'result'. $factory = new DefaultResolvableCallableFactory; $resolved = $factory($callable)->value($container, [2, 3]);