You are here

public function DevelCommands::codeLocate in Devel 4.x

Same name and namespace in other branches
  1. 8.3 src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::codeLocate()
  2. 8 src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::codeLocate()
  3. 8.2 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 256

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 {
    list($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(),
  ];
}