|
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\Driver\Pjb62\Utils\HelperFunctions; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Some annotations for java.lang.Object. |
|
47
|
|
|
* |
|
48
|
|
|
* @see http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html |
|
49
|
|
|
* |
|
50
|
|
|
* @method JavaClass getClass() return object class name |
|
51
|
|
|
* @method bool equals(JavaObject $object) |
|
52
|
|
|
* @method string toString() |
|
53
|
|
|
* @method void offsetUnset($key) |
|
54
|
|
|
* @method void offsetSet($key, $value) |
|
55
|
|
|
* @method mixed offsetGet($key) |
|
56
|
|
|
* @method bool offsetExists($key) |
|
57
|
|
|
* @method mixed getIterator() |
|
58
|
|
|
* @method string getName() |
|
59
|
|
|
*/ |
|
60
|
|
|
class JavaProxy implements JavaType |
|
61
|
|
|
{ |
|
62
|
|
|
protected $__serialID; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var int |
|
66
|
|
|
*/ |
|
67
|
|
|
public $__java; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var string|null |
|
71
|
|
|
*/ |
|
72
|
|
|
public $__signature; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var \Soluble\Japha\Bridge\Driver\Pjb62\Client |
|
76
|
|
|
*/ |
|
77
|
|
|
public $__client; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var GlobalRef|null |
|
81
|
|
|
*/ |
|
82
|
|
|
public $__tempGlobalRef; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param int $java |
|
86
|
|
|
*/ |
|
87
|
111 |
|
public function __construct($java, ?string $signature) |
|
88
|
|
|
{ |
|
89
|
111 |
|
$this->__java = $java; |
|
90
|
111 |
|
$this->__signature = $signature; |
|
91
|
111 |
|
$this->__client = PjbProxyClient::getInstance()->getClient(); |
|
92
|
111 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $type |
|
96
|
|
|
* |
|
97
|
|
|
* @return mixed |
|
98
|
|
|
*/ |
|
99
|
8 |
|
public function __cast(string $type) |
|
100
|
|
|
{ |
|
101
|
8 |
|
return $this->__client->cast($this, $type); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function __sleep() |
|
108
|
|
|
{ |
|
109
|
1 |
|
$args = [$this, HelperFunctions::java_get_session_lifetime()]; |
|
110
|
1 |
|
$this->__serialID = $this->__client->invokeMethod(0, 'serialize', $args); |
|
111
|
1 |
|
$this->__tempGlobalRef = $this->__client->globalRef; |
|
112
|
|
|
|
|
113
|
1 |
|
return ['__serialID', '__tempGlobalRef']; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
public function __wakeup() |
|
117
|
|
|
{ |
|
118
|
1 |
|
$args = [$this->__serialID, HelperFunctions::java_get_session_lifetime()]; |
|
119
|
1 |
|
$this->__client = PjbProxyClient::getInstance()->getClient(); |
|
120
|
1 |
|
if ($this->__tempGlobalRef) { |
|
121
|
1 |
|
$this->__client->globalRef = $this->__tempGlobalRef; |
|
122
|
|
|
} |
|
123
|
1 |
|
$this->__tempGlobalRef = null; |
|
124
|
1 |
|
$this->__java = $this->__client->invokeMethod(0, 'deserialize', $args); |
|
|
|
|
|
|
125
|
1 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Automatically detroy this object |
|
129
|
|
|
* by delegating the unref to the bridge side. |
|
130
|
|
|
*/ |
|
131
|
107 |
|
public function __destruct() |
|
132
|
|
|
{ |
|
133
|
107 |
|
if (isset($this->__client)) { |
|
134
|
107 |
|
$this->__client->unref($this->__java); |
|
135
|
|
|
} |
|
136
|
107 |
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param string $key |
|
140
|
|
|
* |
|
141
|
|
|
* @return mixed |
|
142
|
|
|
*/ |
|
143
|
24 |
|
public function __get(string $key) |
|
144
|
|
|
{ |
|
145
|
24 |
|
return $this->__client->getProperty($this->__java, $key); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param string $key |
|
150
|
|
|
* @param mixed $val |
|
151
|
|
|
*/ |
|
152
|
2 |
|
public function __set(string $key, $val): void |
|
153
|
|
|
{ |
|
154
|
2 |
|
$this->__client->setProperty($this->__java, $key, $val); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
90 |
|
public function __call(string $method, array $args) |
|
158
|
|
|
{ |
|
159
|
90 |
|
return $this->__client->invokeMethod($this->__java, $method, $args); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
69 |
|
public function __toString(): string |
|
166
|
|
|
{ |
|
167
|
|
|
try { |
|
168
|
69 |
|
return (string) $this->__client->invokeMethod(0, 'ObjectToString', [$this]); |
|
169
|
|
|
} catch (Exception\JavaException $ex) { |
|
170
|
|
|
$msg = 'Exception in Java::__toString(): '.HelperFunctions::java_truncate((string) $ex); |
|
171
|
|
|
$this->__client->getLogger()->warning("[soluble-japha] $msg (".__METHOD__.')'); |
|
172
|
|
|
trigger_error($msg, E_USER_WARNING); |
|
173
|
|
|
|
|
174
|
|
|
return ''; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return int |
|
180
|
|
|
*/ |
|
181
|
102 |
|
public function get__java(): int |
|
182
|
|
|
{ |
|
183
|
102 |
|
return $this->__java; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Return java object id. |
|
188
|
|
|
* |
|
189
|
|
|
* @return int |
|
190
|
|
|
*/ |
|
191
|
1 |
|
public function __getJavaInternalObjectId(): int |
|
192
|
|
|
{ |
|
193
|
1 |
|
return $this->__java; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return string |
|
198
|
|
|
*/ |
|
199
|
68 |
|
public function get__signature(): ?string |
|
200
|
|
|
{ |
|
201
|
68 |
|
return $this->__signature; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..