lithium\analysis\Debugger::_definition PHP Method

_definition() protected static method

Locates original location of closures.
protected static _definition ( mixed $reference, integer $callLine ) : mixed
$reference mixed File or class name to inspect.
$callLine integer Line number of class reference.
return mixed Returns the line number where the method called is defined.
    protected static function _definition($reference, $callLine)
    {
        if (file_exists($reference)) {
            foreach (array_reverse(token_get_all(file_get_contents($reference))) as $token) {
                if (!is_array($token) || $token[2] > $callLine) {
                    continue;
                }
                if ($token[0] === T_FUNCTION) {
                    return $token[2];
                }
            }
            return;
        }
        list($class, ) = explode('::', $reference);
        if (!class_exists($class)) {
            return;
        }
        $classRef = new ReflectionClass($class);
        $methodInfo = Inspector::info($reference);
        $methodDef = join("\n", Inspector::lines($classRef->getFileName(), range($methodInfo['start'] + 1, $methodInfo['end'] - 1)));
        foreach (array_reverse(token_get_all("<?php {$methodDef} ?>")) as $token) {
            if (!is_array($token) || $token[2] > $callLine) {
                continue;
            }
            if ($token[0] === T_FUNCTION) {
                return $token[2] + $methodInfo['start'];
            }
        }
    }