1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Penny\Event; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Penny\Route\RouteInfoInterface; |
7
|
|
|
|
8
|
|
|
class FastHttpFlowEvent implements EventInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Representation of an outgoing, client-side request. |
12
|
|
|
* |
13
|
|
|
* @var mixed |
14
|
|
|
*/ |
15
|
|
|
private $request; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Representation of an outgoing, server-side response. |
19
|
|
|
* |
20
|
|
|
* @var mixed |
21
|
|
|
*/ |
22
|
|
|
private $response; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Exception thrown during execution. |
26
|
|
|
* |
27
|
|
|
* @var Exception |
28
|
|
|
*/ |
29
|
|
|
private $exception; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Routing information. |
33
|
|
|
* |
34
|
|
|
* @var RouteInfoInterface |
35
|
|
|
*/ |
36
|
|
|
private $routeInfo; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Event Name |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $name; |
43
|
|
|
|
44
|
|
|
public function __construct($name, $request, $response) |
45
|
|
|
{ |
46
|
|
|
$this->setName($name); |
47
|
|
|
$this->setRequest($request); |
48
|
|
|
$this->setResponse($response); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
|
|
public function getName() |
55
|
|
|
{ |
56
|
|
|
return '/' . $this->name . '/'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
|
|
public function setName($name) |
63
|
|
|
{ |
64
|
|
|
$this->name = $name; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritDoc} |
69
|
|
|
*/ |
70
|
|
|
public function getResponse() |
71
|
|
|
{ |
72
|
|
|
return $this->response; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
public function setResponse($response) |
79
|
|
|
{ |
80
|
|
|
$this->response = $response; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritDoc} |
85
|
|
|
*/ |
86
|
|
|
public function setRequest($request) |
87
|
|
|
{ |
88
|
|
|
$this->request = $request; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
|
|
public function getRequest() |
95
|
|
|
{ |
96
|
|
|
return $this->request; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Route info getter. |
101
|
|
|
* |
102
|
|
|
* @return RouteInfoInterface |
103
|
|
|
*/ |
104
|
|
|
public function getRouteInfo() |
105
|
|
|
{ |
106
|
|
|
return $this->routeInfo; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Route info setter. |
111
|
|
|
* |
112
|
|
|
* @param RouteInfoInterface $routerInfo Routing information. |
113
|
|
|
*/ |
114
|
|
|
public function setRouteInfo(RouteInfoInterface $routerInfo) |
115
|
|
|
{ |
116
|
|
|
$this->routeInfo = $routerInfo; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Exception setter. |
121
|
|
|
* |
122
|
|
|
* @param Exception $exception Exception thrown during execution. |
123
|
|
|
*/ |
124
|
|
|
public function setException(Exception $exception) |
125
|
|
|
{ |
126
|
|
|
$this->exception = $exception; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Exception getter. |
131
|
|
|
* |
132
|
|
|
* @return Exception |
133
|
|
|
*/ |
134
|
|
|
public function getException() |
135
|
|
|
{ |
136
|
|
|
return $this->exception; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* {@inheritDoc} |
141
|
|
|
*/ |
142
|
|
|
public function stopPropagation($flag = true) |
143
|
|
|
{ |
144
|
|
|
if ($flag === true) { |
145
|
|
|
throw new Exception(); |
146
|
|
|
} |
147
|
|
|
return; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|