|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPDaemon\SockJS; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @package Libraries |
|
6
|
|
|
* @subpackage SockJS |
|
7
|
|
|
* @author Vasily Zorin <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
class WebSocketConnectionProxy implements \PHPDaemon\WebSocket\RouteInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use \PHPDaemon\Traits\StaticObjectWatchdog; |
|
12
|
|
|
|
|
13
|
|
|
protected $realConn; |
|
14
|
|
|
|
|
15
|
|
|
protected $sockjs; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* __construct |
|
19
|
|
|
* @param Application $sockjs |
|
20
|
|
|
* @param object $conn |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct($sockjs, $conn) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->sockjs = $sockjs; |
|
25
|
|
|
$this->realConn = $conn; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* __get |
|
30
|
|
|
* @param string $k |
|
31
|
|
|
* @return mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
public function &__get($k) |
|
34
|
|
|
{ |
|
35
|
|
|
if (!isset($this->realConn->{$k})) { |
|
36
|
|
|
return $dummy; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
return $this->realConn->{$k}; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* __set |
|
43
|
|
|
* * @param string $k Key |
|
44
|
|
|
* * @param mixed $$v Value |
|
|
|
|
|
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __set($k, $v) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->realConn->{$k} = $v; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* __isset |
|
54
|
|
|
* @param string $k |
|
55
|
|
|
* @return boolean |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __isset($k) |
|
58
|
|
|
{ |
|
59
|
|
|
return isset($this->realConn->{$k}); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Called when new frame received. |
|
65
|
|
|
* @param string $data Frame's data. |
|
66
|
|
|
* @param string $type Frame's type ("STRING" OR "BINARY"). |
|
67
|
|
|
* @return boolean Success. |
|
|
|
|
|
|
68
|
|
|
*/ |
|
69
|
|
|
public function onFrame($data, $type) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->realConn->onFrame($data, $type); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* __call |
|
76
|
|
|
* @param string $method |
|
77
|
|
|
* @param array $args |
|
78
|
|
|
* @return mixed |
|
79
|
|
|
*/ |
|
80
|
|
|
public function __call($method, $args) |
|
81
|
|
|
{ |
|
82
|
|
|
$func = [$this->realConn, $method]; |
|
83
|
|
|
return $func(...$args); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Sends a frame. |
|
88
|
|
|
* @param string $data Frame's data. |
|
89
|
|
|
* @param integer $type Frame's type. See the constants. |
|
|
|
|
|
|
90
|
|
|
* @param callback $cb Optional. Callback called when the frame is received by client. |
|
|
|
|
|
|
91
|
|
|
* @callback $cb ( ) |
|
92
|
|
|
* @return boolean Success. |
|
93
|
|
|
*/ |
|
94
|
|
|
public function sendFrame($data, $type = null, $cb = null) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->realConn->sendFrame('a' . $this->toJson([$data]), $type, $cb); |
|
|
|
|
|
|
97
|
|
|
return true; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* toJson |
|
102
|
|
|
* @param string $p |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function toJson($p) |
|
106
|
|
|
{ |
|
107
|
|
|
return json_encode($p, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Sends a frame. |
|
112
|
|
|
* @param string $data Frame's data. |
|
113
|
|
|
* @param integer $type Frame's type. See the constants. |
|
|
|
|
|
|
114
|
|
|
* @param callback $cb Optional. Callback called when the frame is received by client. |
|
|
|
|
|
|
115
|
|
|
* @callback $cb ( ) |
|
116
|
|
|
* @return boolean Success. |
|
117
|
|
|
*/ |
|
118
|
|
|
public function sendFrameReal($data, $type = null, $cb = null) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->realConn->sendFrame($data, $type, $cb); |
|
121
|
|
|
return true; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.