function DevelCommands::codeLocate

Same name in this branch
  1. 5.x src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::codeLocate()
Same name in other branches
  1. 4.x src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::codeLocate()

Get source code line for specified function or method.

2 calls to DevelCommands::codeLocate()
DevelCommands::event in src/Drush/Commands/DevelCommands.php
List implementations of a given event and optionally edit one.
DevelCommands::hook in src/Drush/Commands/DevelCommands.php
List implementations of a given hook and optionally edit one.

File

src/Drush/Commands/DevelCommands.php, line 252

Class

DevelCommands

Namespace

Drupal\devel\Drush\Commands

Code

public function codeLocate($function_name) : array {
    // Get implementations in the .install files as well.
    include_once DRUPAL_ROOT . '/core/includes/install.inc';
    drupal_load_updates();
    if (!str_contains($function_name, '::')) {
        if (!function_exists($function_name)) {
            throw new \Exception(dt('Function not found'));
        }
        $reflect = new \ReflectionFunction($function_name);
    }
    else {
        [
            $class,
            $method,
        ] = explode('::', $function_name);
        if (!method_exists($class, $method)) {
            throw new \Exception(dt('Method not found'));
        }
        $reflect = new \ReflectionMethod($class, $method);
    }
    return [
        'file' => $reflect->getFileName(),
        'startline' => $reflect->getStartLine(),
        'endline' => $reflect->getEndLine(),
    ];
}