Skip to content

2.4.0

Choose a tag to compare

@koriym koriym released this 29 Sep 06:13
· 1273 commits to 2.x since this release
  • This release add MethodInvocationProvider which provide methodInvocation object 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.)