Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Console\Event;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\Console\Command\Command;
|
Chris@0
|
15 use Symfony\Component\Console\Input\InputInterface;
|
Chris@0
|
16 use Symfony\Component\Console\Output\OutputInterface;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Allows to handle exception thrown in a command.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
22 */
|
Chris@0
|
23 class ConsoleExceptionEvent extends ConsoleEvent
|
Chris@0
|
24 {
|
Chris@0
|
25 private $exception;
|
Chris@0
|
26 private $exitCode;
|
Chris@0
|
27
|
Chris@0
|
28 public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
|
Chris@0
|
29 {
|
Chris@0
|
30 parent::__construct($command, $input, $output);
|
Chris@0
|
31
|
Chris@0
|
32 $this->setException($exception);
|
Chris@0
|
33 $this->exitCode = (int) $exitCode;
|
Chris@0
|
34 }
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * Returns the thrown exception.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @return \Exception The thrown exception
|
Chris@0
|
40 */
|
Chris@0
|
41 public function getException()
|
Chris@0
|
42 {
|
Chris@0
|
43 return $this->exception;
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * Replaces the thrown exception.
|
Chris@0
|
48 *
|
Chris@0
|
49 * This exception will be thrown if no response is set in the event.
|
Chris@0
|
50 *
|
Chris@0
|
51 * @param \Exception $exception The thrown exception
|
Chris@0
|
52 */
|
Chris@0
|
53 public function setException(\Exception $exception)
|
Chris@0
|
54 {
|
Chris@0
|
55 $this->exception = $exception;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * Gets the exit code.
|
Chris@0
|
60 *
|
Chris@0
|
61 * @return int The command exit code
|
Chris@0
|
62 */
|
Chris@0
|
63 public function getExitCode()
|
Chris@0
|
64 {
|
Chris@0
|
65 return $this->exitCode;
|
Chris@0
|
66 }
|
Chris@0
|
67 }
|