Revision: Fri, 17 May 2024 13:03:33 GMT
v1.0 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
Edit this page

Method Invocations

Tokenizer is able to locate invocations and given parameters for class methods and functions.

Use Spiral\Tokenizer\InvocationsInterface to gain access to such functionality.

Examples

Locate all usages of dump function:

php
public function indexAction(InvocationsInterface $invocations)
{
    dump($invocations->getInvocations(new \ReflectionFunction('dump')));
}

Locate all messages of say method of TranslatorTrait and dump it's parameters:

php
use TranslatorTrait;

public function indexAction(InvocationsInterface $invocations)
{
    $invocations = $invocations->getInvocations(new \ReflectionMethod(
        TranslatorTrait::class,
        'say'
    ));

    foreach ($invocations as $invocation) {
        dump($invocation->getArguments());
    }

    $this->say('hello');
}

Note, current implementation is only capable of locating constructions like self::method(), $this->method() and static::method(), tree based resolutions are currently not implemented (AST support is required).