4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Event;
14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\HttpKernel\HttpKernelInterface;
18 * Allows to create a response for a thrown exception.
20 * Call setResponse() to set the response that will be returned for the
21 * current request. The propagation of this event is stopped as soon as a
24 * You can also call setException() to replace the thrown exception. This
25 * exception will be thrown if no response is set during processing of this
28 * @author Bernhard Schussek <bschussek@gmail.com>
30 class GetResponseForExceptionEvent extends GetResponseEvent
33 * The exception object.
42 private $allowCustomResponseCode = false;
44 public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e)
46 parent::__construct($kernel, $request, $requestType);
48 $this->setException($e);
52 * Returns the thrown exception.
54 * @return \Exception The thrown exception
56 public function getException()
58 return $this->exception;
62 * Replaces the thrown exception.
64 * This exception will be thrown if no response is set in the event.
66 * @param \Exception $exception The thrown exception
68 public function setException(\Exception $exception)
70 $this->exception = $exception;
74 * Mark the event as allowing a custom response code.
76 public function allowCustomResponseCode()
78 $this->allowCustomResponseCode = true;
82 * Returns true if the event allows a custom response code.
86 public function isAllowingCustomResponseCode()
88 return $this->allowCustomResponseCode;