diff options
Diffstat (limited to 'vendor/symfony/console/Event/ConsoleErrorEvent.php')
-rw-r--r-- | vendor/symfony/console/Event/ConsoleErrorEvent.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/symfony/console/Event/ConsoleErrorEvent.php b/vendor/symfony/console/Event/ConsoleErrorEvent.php new file mode 100644 index 0000000..1c0d626 --- /dev/null +++ b/vendor/symfony/console/Event/ConsoleErrorEvent.php | |||
@@ -0,0 +1,58 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
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\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 | * Allows to handle throwables thrown while running a command. | ||
20 | * | ||
21 | * @author Wouter de Jong <wouter@wouterj.nl> | ||
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 | } | ||