Namespace
Drupal\devel\Command
File
-
src/Command/CodeLocationTrait.php
View source
<?php
declare (strict_types=1);
namespace Drupal\devel\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
trait CodeLocationTrait {
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(),
];
}
protected function edit(InputInterface $input, OutputInterface $output, array $location, string $editor) : void {
if (!$input->isInteractive() || !Process::isTtySupported()) {
$output->writeln($location['file'] . ':' . $location['line']);
return;
}
$process = Process::fromShellCommandline($editor . ' "${:DEVEL_FILE}"', timeout: NULL);
$process->setTty(TRUE);
$process->mustRun(env: [
'DEVEL_FILE' => $location['file'],
]);
}
}
Traits
| Title |
Deprecated |
Summary |
| CodeLocationTrait |
|
Locates the source code of callables and opens it in an editor. |