ConsoleCommandEvent.php
1 year ago
ConsoleErrorEvent.php
1 year ago
ConsoleEvent.php
2 years ago
ConsoleSignalEvent.php
2 years ago
ConsoleTerminateEvent.php
2 years ago
ConsoleErrorEvent.php
50 lines
| 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 | namespace Matomo\Dependencies\Symfony\Component\Console\Event; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\Console\Command\Command; |
| 14 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputInterface; |
| 15 | use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface; |
| 16 | /** |
| 17 | * Allows to handle throwables thrown while running a command. |
| 18 | * |
| 19 | * @author Wouter de Jong <wouter@wouterj.nl> |
| 20 | */ |
| 21 | final class ConsoleErrorEvent extends ConsoleEvent |
| 22 | { |
| 23 | private $error; |
| 24 | private $exitCode; |
| 25 | public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, ?Command $command = null) |
| 26 | { |
| 27 | parent::__construct($command, $input, $output); |
| 28 | $this->error = $error; |
| 29 | } |
| 30 | public function getError() : \Throwable |
| 31 | { |
| 32 | return $this->error; |
| 33 | } |
| 34 | public function setError(\Throwable $error) : void |
| 35 | { |
| 36 | $this->error = $error; |
| 37 | } |
| 38 | public function setExitCode(int $exitCode) : void |
| 39 | { |
| 40 | $this->exitCode = $exitCode; |
| 41 | $r = new \ReflectionProperty($this->error, 'code'); |
| 42 | $r->setAccessible(\true); |
| 43 | $r->setValue($this->error, $this->exitCode); |
| 44 | } |
| 45 | public function getExitCode() : int |
| 46 | { |
| 47 | return $this->exitCode ?? (\is_int($this->error->getCode()) && 0 !== $this->error->getCode() ? $this->error->getCode() : 1); |
| 48 | } |
| 49 | } |
| 50 |