| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Console\Event; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Command\Command; |
| 15 |
use Symfony\Component\Console\Input\InputInterface; |
| 16 |
use Symfony\Component\Console\Output\OutputInterface; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
final class ConsoleErrorEvent extends ConsoleEvent |
| 24 |
{ |
| 25 |
private int $exitCode; |
| 26 |
|
| 27 |
public function __construct( |
| 28 |
InputInterface $input, |
| 29 |
OutputInterface $output, |
| 30 |
private \Throwable $error, |
| 31 |
?Command $command = null, |
| 32 |
) { |
| 33 |
parent::__construct($command, $input, $output); |
| 34 |
} |
| 35 |
|
| 36 |
public function getError(): \Throwable |
| 37 |
{ |
| 38 |
return $this->error; |
| 39 |
} |
| 40 |
|
| 41 |
public function setError(\Throwable $error): void |
| 42 |
{ |
| 43 |
$this->error = $error; |
| 44 |
} |
| 45 |
|
| 46 |
public function setExitCode(int $exitCode): void |
| 47 |
{ |
| 48 |
$this->exitCode = $exitCode; |
| 49 |
|
| 50 |
$r = new \ReflectionProperty($this->error, 'code'); |
| 51 |
$r->setValue($this->error, $this->exitCode); |
| 52 |
} |
| 53 |
|
| 54 |
public function getExitCode(): int |
| 55 |
{ |
| 56 |
return $this->exitCode ?? (\is_int($this->error->getCode()) && 0 !== $this->error->getCode() ? $this->error->getCode() : 1); |
| 57 |
} |
| 58 |
} |