function CodeLocationTrait::locate

Describes where a callable is defined.

Return value

array{name: string, file: string, line: int} The function or Class::method name, its file and its first line.

2 calls to CodeLocationTrait::locate()
DevelEventCommand::getImplementations in src/Command/DevelEventCommand.php
Finds the listeners of an event.
DevelHookCommand::getImplementations in src/Command/DevelHookCommand.php
Finds the implementations of a hook.

File

src/Command/CodeLocationTrait.php, line 22

Class

CodeLocationTrait
Locates the source code of callables and opens it in an editor.

Namespace

Drupal\devel\Command

Code

protected function locate(callable $callable) : array {
  $reflection = new \ReflectionFunction(\Closure::fromCallable($callable));
  is_callable($callable, FALSE, $name);
  if ($callable instanceof \Closure) {
    $name = $reflection->getName();
  }
  return [
    'name' => $name,
    'file' => (string) $reflection->getFileName(),
    'line' => (int) $reflection->getStartLine(),
  ];
}