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\HTTP\Dispatcher;
13
14 use ICanBoogie\Event;
15 use ICanBoogie\HTTP\Dispatcher;
16 use ICanBoogie\HTTP\Request;
17 use ICanBoogie\HTTP\Response;
18
19 /**
20 * Event class for the `ICanBoogie\HTTP\Dispatcher::dispatch` event.
21 *
22 * Third parties may use this event to alter the response before it is returned by the dispatcher.
23 *
24 * @property-read Request $request
25 * @property Response $response
26 */
27 class DispatchEvent extends Event
28 {
29 /**
30 * The request.
31 *
32 * @var Request
33 */
34 private $request;
35
36 protected function get_request()
37 {
38 return $this->request;
39 }
40
41 /**
42 * Reference to the response.
43 *
44 * @var Response
45 */
46 private $response;
47
48 protected function get_response()
49 {
50 return $this->response;
51 }
52
53 protected function set_response(Response $response = null)
54 {
55 $this->response = $response;
56 }
57
58 /**
59 * The event is constructed with the type `dispatch`.
60 *
61 * @param Dispatcher $target
62 * @param Request $request
63 * @param Response|null $response Reference to the response.
64 */
65 public function __construct(Dispatcher $target, Request $request, Response &$response = null)
66 {
67 $this->request = $request;
68 $this->response = &$response;
69
70 parent::__construct($target, 'dispatch');
71 }
72 }
73