2
2
3
3
namespace Rx \Websocket ;
4
4
5
+ use Psr \Http \Message \RequestInterface ;
6
+ use Psr \Http \Message \ResponseInterface ;
5
7
use Rx \Websocket \RFC6455 \Messaging \Protocol \Frame ;
6
8
use Rx \Observable ;
7
9
use Rx \Observable \AnonymousObservable ;
@@ -27,21 +29,34 @@ class MessageSubject extends Subject
27
29
/** @var string */
28
30
private $ subProtocol ;
29
31
32
+ /** @var RequestInterface */
33
+ private $ request ;
34
+
35
+ /** @var ResponseInterface */
36
+ private $ response ;
37
+
30
38
/**
31
39
* ConnectionSubject constructor.
32
40
* @param ObservableInterface $rawDataIn
33
41
* @param ObserverInterface $rawDataOut
34
42
* @param bool $mask
35
43
* @param bool $useMessageObject
36
44
* @param string $subProtocol
45
+ * @param RequestInterface $request
46
+ * @param ResponseInterface $response
37
47
*/
38
48
public function __construct (
39
49
ObservableInterface $ rawDataIn ,
40
50
ObserverInterface $ rawDataOut ,
41
51
$ mask = false ,
42
52
$ useMessageObject = false ,
43
- $ subProtocol = ""
53
+ $ subProtocol = "" ,
54
+ RequestInterface $ request ,
55
+ ResponseInterface $ response
44
56
) {
57
+ $ this ->request = $ request ;
58
+ $ this ->response = $ response ;
59
+
45
60
$ this ->rawDataIn = new AnonymousObservable (function ($ observer ) use ($ rawDataIn ) {
46
61
return $ rawDataIn ->subscribe ($ observer );
47
62
});
@@ -92,10 +107,12 @@ function () use ($frames) {
92
107
->filter (function (Frame $ frame ) {
93
108
return $ frame ->getOpcode () === $ frame ::OP_PING ;
94
109
})
95
- ->subscribe (new CallbackObserver (function (Frame $ frame ) {
96
- $ pong = new Frame ($ frame ->getPayload (), true , Frame::OP_PONG );
97
- $ this ->sendFrame ($ pong );
98
- }));
110
+ ->subscribe (new CallbackObserver (
111
+ function (Frame $ frame ) {
112
+ $ pong = new Frame ($ frame ->getPayload (), true , Frame::OP_PONG );
113
+ $ this ->sendFrame ($ pong );
114
+ }
115
+ ));
99
116
100
117
$ frames
101
118
->filter (function (Frame $ frame ) {
@@ -177,4 +194,20 @@ public function getSubProtocol()
177
194
{
178
195
return $ this ->subProtocol ;
179
196
}
197
+
198
+ /**
199
+ * @return RequestInterface
200
+ */
201
+ public function getRequest ()
202
+ {
203
+ return $ this ->request ;
204
+ }
205
+
206
+ /**
207
+ * @return ResponseInterface
208
+ */
209
+ public function getResponse ()
210
+ {
211
+ return $ this ->response ;
212
+ }
180
213
}
0 commit comments