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:before` event.
21 *
22 * Third parties may use this event to provide a response to the request before the dispatchers
23 * are invoked. The event is usually used by third parties to redirect requests or provide cached
24 * responses.
25 *
26 * @property-read Request $request
27 * @property Response $response
28 */
29 class BeforeDispatchEvent extends Event
30 {
31 /**
32 * The request.
33 *
34 * @var Request
35 */
36 private $request;
37
38 protected function get_request()
39 {
40 return $this->request;
41 }
42
43 /**
44 * Reference to the response.
45 *
46 * @var Response
47 */
48 private $response;
49
50 protected function get_response()
51 {
52 return $this->response;
53 }
54
55 protected function set_response(Response $response = null)
56 {
57 $this->response = $response;
58 }
59
60 /**
61 * The event is constructed with the type `dispatch:before`.
62 *
63 * @param Dispatcher $target
64 * @param Request $request
65 * @param Response|null $response Reference to the response.
66 */
67 public function __construct(Dispatcher $target, Request $request, Response &$response = null)
68 {
69 $this->request = $request;
70 $this->response = &$response;
71
72 parent::__construct($target, 'dispatch:before');
73 }
74 }
75