function DevelCommands::codeLocate

Same name in this branch
  1. 5.x src/Drush/Commands/DevelCommands.php \Drupal\devel\Drush\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/Commands/DevelCommands.php
List implementations of a given event and optionally edit one.
DevelCommands::hook in src/Commands/DevelCommands.php
List implementations of a given hook and optionally edit one.

File

src/Commands/DevelCommands.php, line 277

Class

DevelCommands
Class DevelCommands.

Namespace

Drupal\devel\Commands

Code

public function codeLocate($function_name) {
    // Get implementations in the .install files as well.
    include_once './core/includes/install.inc';
    drupal_load_updates();
    if (strpos($function_name, '::') === FALSE) {
        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(),
    ];
}