1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.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 ICanBoogie\Exception;
13
14 use ICanBoogie\Event;
15 use ICanBoogie\HTTP\Request;
16 use ICanBoogie\HTTP\Response;
17
18 /**
19 * Event class for the `Exception:rescue` event type.
20 *
21 * Third parties may use this event to provide a response for the exception.
22 *
23 * @property \Exception $exception
24 * @property-read Request $request
25 * @property Response $response
26 */
27 class RescueEvent extends Event
28 {
29 /**
30 * Reference to the response.
31 *
32 * @var Response
33 */
34 private $response;
35
36 protected function get_response()
37 {
38 return $this->response;
39 }
40
41 protected function set_response(Response $response = null)
42 {
43 $this->response = $response;
44 }
45
46 /**
47 * Reference to the exception.
48 *
49 * @var \Exception
50 */
51 private $exception;
52
53 protected function get_exception()
54 {
55 return $this->exception;
56 }
57
58 protected function set_exception(\Exception $exception)
59 {
60 $this->exception = $exception;
61 }
62
63 /**
64 * The request.
65 *
66 * @var Request
67 */
68 private $request;
69
70 protected function get_request()
71 {
72 return $this->request;
73 }
74
75 /**
76 * The event is constructed with the type `rescue`.
77 *
78 * @param \Exception $target
79 * @param Request $request The request.
80 * @param Response|null $response Reference to the response.
81 */
82 public function __construct(\Exception &$target, Request $request, Response &$response = null)
83 {
84 $this->response = &$response;
85 $this->exception = &$target;
86 $this->request = $request;
87
88 parent::__construct($target, 'rescue');
89 }
90 }
91