8000 [Console] Fix invokable command profiler representation · symfonyaml/symfony@8c6f63f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c6f63f

Browse files
committed
[Console] Fix invokable command profiler representation
1 parent bc91d81 commit 8c6f63f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/Console/Command/TraceableCommand.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class TraceableCommand extends Command implements SignalableCommandInterfa
4545
/** @var array<string, mixed> */
4646
public array $interactiveInputs = [];
4747
public array $handledSignals = [];
48+
public ?array $invokableCommandInfo = null;
4849

4950
public function __construct(
5051
Command $command,
@@ -171,6 +172,18 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
171172
*/
172173
public function setCode(callable $code): static
173174
{
175+
if ($code instanceof InvokableCommand) {
176+
$r = new \ReflectionFunction(\Closure::bind(function () {
177+
return $this->code;
178+
}, $code, InvokableCommand::class)());
179+
180+
$this->invokableCommandInfo = [
181+
'class' => $r->getClosureScopeClass()->name,
182+
'file' => $r->getFileName(),
183+
'line' => $r->getStartLine(),
184+
];
185+
}
186+
174187
$this->command->setCode($code);
175188

176189
return parent::setCode(function (InputInterface $input, OutputInterface $output) use ($code): int {

src/Symfony/Component/Console/DataCollector/CommandDataCollector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
3737
$application = $command->getApplication();
3838

3939
$this->data = [
40-
'command' => $this->cloneVar($command->command),
40+
'command' => $command->invokableCommandInfo ?? $this->cloneVar($command->command),
4141
'exit_code' => $command->exitCode,
4242
'interrupted_by_signal' => $command->interruptedBySignal,
4343
'duration' => $command->duration,
@@ -95,6 +95,10 @@ public function getName(): string
9595
*/
9696
public function getCommand(): array
9797
{
98+
if (\is_array($this->data['command'])) {
99+
return $this->data['command'];
100+
}
101+
98102
$class = $this->data['command']->getType();
99103
$r = new \ReflectionMethod($class, 'execute');
100104

0 commit comments

Comments
 (0)
0