1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* soluble-japha / PHPJavaBridge driver client. |
7
|
|
|
* |
8
|
|
|
* Refactored version of phpjababridge's Java.inc file compatible |
9
|
|
|
* with php java bridge 6.2 |
10
|
|
|
* |
11
|
|
|
* |
12
|
|
|
* @credits http://php-java-bridge.sourceforge.net/pjb/ |
13
|
|
|
* |
14
|
|
|
* @see http://github.com/belgattitude/soluble-japha |
15
|
|
|
* |
16
|
|
|
* @author Jost Boekemeier |
17
|
|
|
* @author Vanvelthem Sébastien (refactoring and fixes from original implementation) |
18
|
|
|
* @license MIT |
19
|
|
|
* |
20
|
|
|
* The MIT License (MIT) |
21
|
|
|
* Copyright (c) 2014-2017 Jost Boekemeier |
22
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
23
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
24
|
|
|
* in the Software without restriction, including without limitation the rights |
25
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
26
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
27
|
|
|
* furnished to do so, subject to the following conditions: |
28
|
|
|
* |
29
|
|
|
* The above copyright notice and this permission notice shall be included in |
30
|
|
|
* all copies or substantial portions of the Software. |
31
|
|
|
* |
32
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
33
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
34
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
35
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
36
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
37
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
38
|
|
|
* THE SOFTWARE. |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
namespace Soluble\Japha\Bridge\Driver\Pjb62; |
42
|
|
|
|
43
|
|
|
use Soluble\Japha\Bridge\Exception; |
44
|
|
|
|
45
|
|
|
class EmptyChannel |
46
|
|
|
{ |
47
|
|
|
/** |
48
|
|
|
* @var SocketHandler |
49
|
|
|
*/ |
50
|
|
|
protected $handler; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string|null |
54
|
|
|
*/ |
55
|
|
|
private $res; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var int |
59
|
|
|
*/ |
60
|
|
|
protected $recv_size; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var int |
64
|
|
|
*/ |
65
|
|
|
protected $send_size; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param SocketHandler $handler |
69
|
|
|
* @param int $recv_size |
70
|
|
|
* @param int $send_size |
71
|
|
|
*/ |
72
|
30 |
|
public function __construct(SocketHandler $handler, $recv_size, $send_size) |
73
|
|
|
{ |
74
|
30 |
|
$this->send_size = $send_size; |
75
|
30 |
|
$this->recv_size = $recv_size; |
76
|
30 |
|
$this->handler = $handler; |
77
|
30 |
|
} |
78
|
|
|
|
79
|
|
|
public function fwrite(string $data): ?int |
80
|
|
|
{ |
81
|
|
|
return $this->handler->fwrite($data); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function fread(int $size): ?string |
85
|
|
|
{ |
86
|
|
|
return $this->handler->fread($size); |
87
|
|
|
} |
88
|
|
|
|
89
|
8 |
|
protected function getKeepAliveA(): string |
90
|
|
|
{ |
91
|
8 |
|
return '<F p="A" />'; |
92
|
|
|
} |
93
|
|
|
|
94
|
17 |
|
protected function getKeepAliveE(): string |
95
|
|
|
{ |
96
|
17 |
|
return '<F p="E" />'; |
97
|
|
|
} |
98
|
|
|
|
99
|
17 |
|
public function getKeepAlive(): string |
100
|
|
|
{ |
101
|
17 |
|
return $this->getKeepAliveE(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @throws Exception\RuntimeException |
106
|
|
|
*/ |
107
|
|
|
protected function error(): void |
108
|
|
|
{ |
109
|
|
|
$msg = 'An unchecked exception occured during script execution. Please check the server log files for details.'; |
110
|
|
|
throw new Exception\RuntimeException($msg); |
111
|
|
|
} |
112
|
|
|
|
113
|
8 |
|
protected function checkA($peer): void |
114
|
|
|
{ |
115
|
8 |
|
$val = $this->res[6]; |
116
|
8 |
|
if ($val !== 'A') { |
117
|
|
|
fclose($peer); |
118
|
|
|
} |
119
|
8 |
|
if ($val !== 'A' && $val !== 'E') { |
120
|
|
|
$this->error(); |
121
|
|
|
} |
122
|
8 |
|
} |
123
|
|
|
|
124
|
|
|
public function checkE(): void |
125
|
|
|
{ |
126
|
|
|
$val = $this->res[6]; |
127
|
|
|
if ($val !== 'E') { |
128
|
|
|
$this->error(); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
8 |
|
protected function keepAliveS(): void |
133
|
|
|
{ |
134
|
8 |
|
$this->res = $this->fread(10); |
135
|
8 |
|
} |
136
|
|
|
|
137
|
|
|
protected function keepAliveSC(): void |
138
|
|
|
{ |
139
|
|
|
$this->res = $this->fread(10); |
140
|
|
|
$this->fwrite(''); |
141
|
|
|
$this->fread($this->recv_size); |
142
|
|
|
} |
143
|
|
|
|
144
|
17 |
|
protected function keepAliveH(): void |
145
|
|
|
{ |
146
|
17 |
|
$this->res = $this->handler->read(10); |
147
|
|
|
} |
148
|
|
|
|
149
|
17 |
|
public function keepAlive(): void |
150
|
|
|
{ |
151
|
17 |
|
$this->keepAliveH(); |
152
|
|
|
$this->checkE(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function shutdownBrokenConnection(string $msg = ''): void |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
// so nothing |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.