| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Symfony\Component\Console\Debug; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Command\TraceableCommand; |
| 15 |
use Symfony\Component\HttpFoundation\Request; |
| 16 |
use Symfony\Component\HttpFoundation\Response; |
| 17 |
|
| 18 |
/** |
| 19 |
* @internal |
| 20 |
*/ |
| 21 |
final class CliRequest extends Request |
| 22 |
{ |
| 23 |
public function __construct( |
| 24 |
public readonly TraceableCommand $command, |
| 25 |
) { |
| 26 |
parent::__construct( |
| 27 |
attributes: ['_controller' => $command->command::class, '_virtual_type' => 'command'], |
| 28 |
server: $_SERVER, |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
// Methods below allow to populate a profile, thus enable search and filtering |
| 33 |
public function getUri(): string |
| 34 |
{ |
| 35 |
if ($this->server->has('SYMFONY_CLI_BINARY_NAME')) { |
| 36 |
$binary = $this->server->get('SYMFONY_CLI_BINARY_NAME').' console'; |
| 37 |
} else { |
| 38 |
$binary = $this->server->get('argv')[0]; |
| 39 |
} |
| 40 |
|
| 41 |
return $binary.' '.$this->command->input; |
| 42 |
} |
| 43 |
|
| 44 |
public function getMethod(): string |
| 45 |
{ |
| 46 |
return $this->command->isInteractive ? 'INTERACTIVE' : 'BATCH'; |
| 47 |
} |
| 48 |
|
| 49 |
public function getResponse(): Response |
| 50 |
{ |
| 51 |
return new class($this->command->exitCode) extends Response { |
| 52 |
public function __construct(private readonly int $exitCode) |
| 53 |
{ |
| 54 |
parent::__construct(); |
| 55 |
} |
| 56 |
|
| 57 |
public function getStatusCode(): int |
| 58 |
{ |
| 59 |
return $this->exitCode; |
| 60 |
} |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
public function getClientIp(): string |
| 65 |
{ |
| 66 |
$application = $this->command->getApplication(); |
| 67 |
|
| 68 |
return $application->getName().' '.$application->getVersion(); |
| 69 |
} |
| 70 |
} |