1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Event that is passed to graviton.rest.event listeners |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\RestBundle\Event; |
7
|
|
|
|
8
|
|
|
use Symfony\Component\EventDispatcher\Event; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
use Graviton\RestBundle\Controller\RestController; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Event that is passed to graviton.rest.event listeners |
15
|
|
|
* |
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
18
|
|
|
* @link http://swisscom.ch |
19
|
|
|
*/ |
20
|
|
|
class RestEvent extends Event |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Request object |
25
|
|
|
* |
26
|
|
|
* @var \Symfony\Component\HttpFoundation\Request |
27
|
|
|
*/ |
28
|
|
|
private $request = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Response object |
32
|
|
|
* |
33
|
|
|
* @var \Symfony\Component\HttpFoundation\Response |
34
|
|
|
*/ |
35
|
|
|
private $response = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Controller which handles the request |
39
|
|
|
* |
40
|
|
|
* @var \Graviton\RestBundle\Controller\RestController |
41
|
|
|
*/ |
42
|
|
|
private $controller = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Is there a response? |
46
|
|
|
* |
47
|
|
|
* @return boolean |
48
|
|
|
*/ |
49
|
|
|
public function hasResponse() |
50
|
|
|
{ |
51
|
|
|
return null !== $this->response; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the request object |
56
|
|
|
* |
57
|
|
|
* @param Request $request Request |
58
|
|
|
* |
59
|
|
|
* @return \Graviton\RestBundle\Event\RestEvent $this This |
60
|
|
|
*/ |
61
|
10 |
|
public function setRequest(Request $request) |
|
|
|
|
62
|
|
|
{ |
63
|
10 |
|
$this->request = $request; |
64
|
|
|
|
65
|
10 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the request |
70
|
|
|
* |
71
|
|
|
* @return Request |
72
|
|
|
*/ |
73
|
10 |
|
public function getRequest() |
74
|
|
|
{ |
75
|
10 |
|
return $this->request; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Set the response object and DON'T stop propagation -> Do this yourself |
80
|
|
|
* if you need it... |
81
|
|
|
* |
82
|
|
|
* @param Response $response Response object |
83
|
|
|
* |
84
|
|
|
* @return \Graviton\RestBundle\Event\RestEvent $this This object |
85
|
|
|
*/ |
86
|
|
|
public function setResponse(Response $response) |
87
|
|
|
{ |
88
|
|
|
$this->response = $response; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the response object |
95
|
|
|
* |
96
|
|
|
* @return Response $response Response object |
97
|
|
|
*/ |
98
|
|
|
public function getResponse() |
99
|
|
|
{ |
100
|
|
|
return $this->response; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set the controller for this request |
105
|
|
|
* At the moment, the MainController doesn't extend the RestController. |
106
|
|
|
* As soon this is refactored, we can add a type hint to the method |
107
|
|
|
* |
108
|
|
|
* @param RestController $controller Controller |
109
|
|
|
* |
110
|
|
|
* @return \Graviton\RestBundle\Event\RestEvent $this This object |
111
|
|
|
*/ |
112
|
|
|
public function setController($controller) |
113
|
|
|
{ |
114
|
|
|
$this->controller = $controller; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get the controller |
121
|
|
|
* |
122
|
|
|
* @return RestController $controller Controller |
123
|
|
|
*/ |
124
|
|
|
public function getController() |
125
|
|
|
{ |
126
|
|
|
return $this->controller; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|