1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slince/spike package. |
5
|
|
|
* |
6
|
|
|
* (c) Slince <[email protected]> |
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 Spike\Server\ChunkServer; |
13
|
|
|
|
14
|
|
|
use React\Socket\ConnectionInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @method write($data) |
18
|
|
|
* @method on($eventName, callable $listener) |
19
|
|
|
* @method pipe($dst, array $options = []); |
20
|
|
|
* @method removeListener($eventName, callable $listener); |
21
|
|
|
* @method removeAllListeners($eventName = null); |
22
|
|
|
* @method end($data = null); |
23
|
|
|
* @method pause(); |
24
|
|
|
* @method resume(); |
25
|
|
|
*/ |
26
|
|
|
class PublicConnection |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ConnectionInterface |
30
|
|
|
*/ |
31
|
|
|
protected $connection; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $initBuffer; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $id; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The create time. |
45
|
|
|
* |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
protected $createAt; |
49
|
|
|
|
50
|
|
|
public function __construct(ConnectionInterface $connection, $initBuffer = '') |
51
|
|
|
{ |
52
|
|
|
$this->connection = $connection; |
53
|
|
|
$this->initBuffer = $initBuffer; |
54
|
|
|
$this->id = spl_object_hash($connection); |
55
|
|
|
$this->createAt = microtime(true); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @codeCoverageIgnore |
60
|
|
|
*/ |
61
|
|
|
public function __call($name, $arguments) |
62
|
|
|
{ |
63
|
|
|
return call_user_func_array([$this->connection, $name], $arguments); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getId() |
70
|
|
|
{ |
71
|
|
|
return $this->id; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return ConnectionInterface |
76
|
|
|
*/ |
77
|
|
|
public function getConnection() |
78
|
|
|
{ |
79
|
|
|
return $this->connection; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $initBuffer |
84
|
|
|
*/ |
85
|
|
|
public function setInitBuffer($initBuffer) |
86
|
|
|
{ |
87
|
|
|
$this->initBuffer = $initBuffer; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getInitBuffer() |
94
|
|
|
{ |
95
|
|
|
return $this->initBuffer; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Gets the waiting duration of the connection. |
100
|
|
|
* |
101
|
|
|
* @return float |
102
|
|
|
*/ |
103
|
|
|
public function getWaitingDuration() |
104
|
|
|
{ |
105
|
|
|
return microtime(true) - $this->createAt; |
106
|
|
|
} |
107
|
|
|
} |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.