Repository navigation
2.4.0
- This release add
MethodInvocationProviderwhich providemethodInvocationobject which holds data of passing parameters or target object. You can inject in Provider's constructor.
For example, $db is determined by $id in getUser() method.
use Ray\Di\Di\Assisted;
class FakeAssistedParamsConsumer
{
/**
* @param string $id
* @param string $db
*
* @Assisted("db")
*
* @return array [int, FakeAbstractDb]
*/
public function getUser($id, FakeAbstractDb $db = null)
{
return [$id, $db];
}
}$db can be provided by the value of $id
class FakeAssistedDbProvider implements ProviderInterface
{
/**
* @var MethodInvocationProvider
*/
private $invocationProvider;
public function __construct(MethodInvocationProvider $invocationProvider)
{
$this->invocationProvider = $invocationProvider;
}
public function get()
{
$parameters = $this->invocationProvider->get()->getArguments()->getArrayCopy();
list($id) = $parameters;
return new FakeAssistedDb($id);
}
}- Drop PHP version 5.4 and 5.5 support. (5.6 and 7.0 are supported.)