|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/** |
|
5
|
|
|
* soluble-japha / PHPJavaBridge driver client. |
|
6
|
|
|
* |
|
7
|
|
|
* Refactored version of phpjababridge's Java.inc file compatible |
|
8
|
|
|
* with php java bridge 6.2 |
|
9
|
|
|
* |
|
10
|
|
|
* |
|
11
|
|
|
* @credits http://php-java-bridge.sourceforge.net/pjb/ |
|
12
|
|
|
* |
|
13
|
|
|
* @see http://github.com/belgattitude/soluble-japha |
|
14
|
|
|
* |
|
15
|
|
|
* @author Jost Boekemeier |
|
16
|
|
|
* @author Vanvelthem Sébastien (refactoring and fixes from original implementation) |
|
17
|
|
|
* @license MIT |
|
18
|
|
|
* |
|
19
|
|
|
* The MIT License (MIT) |
|
20
|
|
|
* Copyright (c) 2014-2017 Jost Boekemeier |
|
21
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
22
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
23
|
|
|
* in the Software without restriction, including without limitation the rights |
|
24
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
25
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
26
|
|
|
* furnished to do so, subject to the following conditions: |
|
27
|
|
|
* |
|
28
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
29
|
|
|
* all copies or substantial portions of the Software. |
|
30
|
|
|
* |
|
31
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
32
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
33
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
34
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
35
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
36
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
37
|
|
|
* THE SOFTWARE. |
|
38
|
|
|
* |
|
39
|
|
|
* @method string getName() |
|
40
|
|
|
* @method string forName() |
|
41
|
|
|
*/ |
|
42
|
|
|
|
|
43
|
|
|
namespace Soluble\Japha\Bridge\Driver\Pjb62; |
|
44
|
|
|
|
|
45
|
|
|
use Soluble\Japha\Interfaces; |
|
46
|
|
|
|
|
47
|
|
|
abstract class AbstractJava implements \IteratorAggregate, \ArrayAccess, JavaType, Interfaces\JavaObject |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @var Client|string|null |
|
51
|
|
|
*/ |
|
52
|
|
|
public $__client; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var JavaType&JavaProxy |
|
56
|
|
|
*/ |
|
57
|
|
|
public $__delegate; |
|
58
|
|
|
protected $__serialID; |
|
59
|
|
|
public $__factory; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var int |
|
63
|
|
|
*/ |
|
64
|
|
|
public $__java; |
|
65
|
|
|
/** |
|
66
|
|
|
* @var string|null |
|
67
|
|
|
*/ |
|
68
|
|
|
public $__signature; |
|
69
|
|
|
public $__cancelProxyCreationTag; |
|
70
|
|
|
|
|
71
|
|
|
protected function __createDelegate(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$proxy = $this->__factory->create($this->__java, $this->__signature); |
|
74
|
|
|
$this->__delegate = $proxy; |
|
75
|
|
|
$this->__java = $proxy->__java; |
|
76
|
|
|
$this->__signature = $proxy->__signature; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $type |
|
81
|
|
|
* |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
public function __cast(string $type) |
|
85
|
|
|
{ |
|
86
|
|
|
if (!isset($this->__delegate)) { |
|
87
|
|
|
$this->__createDelegate(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $this->__delegate->__cast($type); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function __sleep() |
|
97
|
|
|
{ |
|
98
|
1 |
|
if (!isset($this->__delegate)) { |
|
99
|
|
|
$this->__createDelegate(); |
|
100
|
|
|
} |
|
101
|
1 |
|
$this->__delegate->__sleep(); |
|
102
|
|
|
|
|
103
|
1 |
|
return ['__delegate']; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
1 |
|
public function __wakeup() |
|
107
|
|
|
{ |
|
108
|
1 |
|
if (!isset($this->__delegate)) { |
|
109
|
|
|
$this->__createDelegate(); |
|
110
|
|
|
} |
|
111
|
1 |
|
$this->__delegate->__wakeup(); |
|
112
|
1 |
|
$this->__java = $this->__delegate->get__java(); |
|
113
|
1 |
|
$this->__client = $this->__delegate->get__signature(); |
|
114
|
1 |
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Delegate the magic method __get() to the java object |
|
118
|
|
|
* to access the Java object properties (and not the PHP |
|
119
|
|
|
* remote proxied object). |
|
120
|
|
|
* |
|
121
|
|
|
* @throws \Exception Depending on ThrowExceptionProxy |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $key |
|
124
|
|
|
* |
|
125
|
|
|
* @return mixed |
|
126
|
|
|
*/ |
|
127
|
2 |
|
public function __get(string $key) |
|
128
|
|
|
{ |
|
129
|
2 |
|
if (!isset($this->__delegate)) { |
|
130
|
|
|
$this->__createDelegate(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
2 |
|
return $this->__delegate->__get($key); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Delegate the magic method __set() to the java object |
|
138
|
|
|
* to access the Java object properties (and not the PHP |
|
139
|
|
|
* remote proxied object). |
|
140
|
|
|
* |
|
141
|
|
|
* @throws \Exception Depending on ThrowExceptionProxy |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $key |
|
144
|
|
|
* @param mixed $val |
|
145
|
|
|
*/ |
|
146
|
2 |
|
public function __set(string $key, $val): void |
|
147
|
|
|
{ |
|
148
|
2 |
|
if (!isset($this->__delegate)) { |
|
149
|
|
|
$this->__createDelegate(); |
|
150
|
|
|
} |
|
151
|
2 |
|
$this->__delegate->__set($key, $val); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Delegate the magic method __cal() to the java object |
|
156
|
|
|
* to access the Java object method (and not the PHP |
|
157
|
|
|
* remote proxied object). |
|
158
|
|
|
* |
|
159
|
|
|
* @throws \Exception Depending on ThrowExceptionProxy |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $method |
|
162
|
|
|
* @param array $args |
|
163
|
|
|
* |
|
164
|
|
|
* @return mixed |
|
165
|
|
|
*/ |
|
166
|
77 |
|
public function __call(string $method, array $args) |
|
167
|
|
|
{ |
|
168
|
77 |
|
if (!isset($this->__delegate)) { |
|
169
|
|
|
$this->__createDelegate(); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
77 |
|
return $this->__delegate->__call($method, $args); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @param mixed|null ...$args arguments |
|
177
|
|
|
* |
|
178
|
|
|
* @return ObjectIterator |
|
179
|
|
|
*/ |
|
180
|
8 |
|
public function getIterator(...$args) |
|
181
|
|
|
{ |
|
182
|
8 |
|
if (!isset($this->__delegate)) { |
|
183
|
|
|
$this->__createDelegate(); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
8 |
|
if (empty($args)) { |
|
187
|
8 |
|
return $this->__delegate->getIterator(); |
|
|
|
|
|
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
1 |
|
return $this->__call('getIterator', $args); |
|
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @param string|int $idx |
|
195
|
|
|
* @param mixed|null ...$args |
|
196
|
|
|
* |
|
197
|
|
|
* @return bool |
|
198
|
|
|
*/ |
|
199
|
3 |
|
public function offsetExists($idx, ...$args): bool |
|
200
|
|
|
{ |
|
201
|
3 |
|
if (!isset($this->__delegate)) { |
|
202
|
|
|
$this->__createDelegate(); |
|
203
|
|
|
} |
|
204
|
3 |
|
if (empty($args)) { |
|
205
|
2 |
|
return $this->__delegate->offsetExists($idx); |
|
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
// In case we supplied more arguments than what ArrayAccess |
|
209
|
|
|
// suggest, let's try for a java method called offsetExists |
|
210
|
|
|
// with all the provided parameters |
|
211
|
1 |
|
array_unshift($args, $idx); // Will add idx at the beginning of args params |
|
212
|
|
|
|
|
213
|
1 |
|
return $this->__call('offsetExists', $args); |
|
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param string|int $idx |
|
218
|
|
|
* @param mixed|null ...$args additional arguments |
|
219
|
|
|
* |
|
220
|
|
|
* @return mixed |
|
221
|
|
|
*/ |
|
222
|
4 |
|
public function offsetGet($idx, ...$args) |
|
223
|
|
|
{ |
|
224
|
4 |
|
if (!isset($this->__delegate)) { |
|
225
|
|
|
$this->__createDelegate(); |
|
226
|
|
|
} |
|
227
|
4 |
|
if (empty($args)) { |
|
228
|
4 |
|
return $this->__delegate->offsetGet($idx); |
|
|
|
|
|
|
229
|
|
|
} |
|
230
|
1 |
|
array_unshift($args, $idx); |
|
231
|
|
|
|
|
232
|
1 |
|
return $this->__call('offsetGet', $args); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @param string|int $idx |
|
237
|
|
|
* @param mixed $val |
|
238
|
|
|
* @param mixed|null ...$args additional arguments |
|
239
|
|
|
* |
|
240
|
|
|
* @return mixed |
|
241
|
|
|
*/ |
|
242
|
3 |
|
public function offsetSet($idx, $val, ...$args) |
|
243
|
|
|
{ |
|
244
|
3 |
|
if (!isset($this->__delegate)) { |
|
245
|
|
|
$this->__createDelegate(); |
|
246
|
|
|
} |
|
247
|
3 |
|
if (empty($args)) { |
|
248
|
3 |
|
return $this->__delegate->offsetSet($idx, $val); |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
1 |
|
array_unshift($args, $idx, $val); |
|
252
|
|
|
|
|
253
|
1 |
|
return $this->__call('offsetSet', $args); |
|
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @param mixed $idx |
|
258
|
|
|
* @param mixed|null ...$args additional arguments |
|
259
|
|
|
* |
|
260
|
|
|
* @return mixed|void |
|
261
|
|
|
*/ |
|
262
|
1 |
|
public function offsetUnset($idx, ...$args) |
|
263
|
|
|
{ |
|
264
|
1 |
|
if (!isset($this->__delegate)) { |
|
265
|
|
|
$this->__createDelegate(); |
|
266
|
|
|
} |
|
267
|
1 |
|
if (empty($args)) { |
|
268
|
1 |
|
return $this->__delegate->offsetUnset($idx); |
|
|
|
|
|
|
269
|
|
|
} |
|
270
|
1 |
|
array_unshift($args, $idx); |
|
271
|
|
|
|
|
272
|
1 |
|
return $this->__call('offsetUnset', $args); |
|
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @return int |
|
277
|
|
|
*/ |
|
278
|
57 |
|
public function get__java(): int |
|
279
|
|
|
{ |
|
280
|
57 |
|
return $this->__java; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Return java object id. |
|
285
|
|
|
* |
|
286
|
|
|
* @return int |
|
287
|
|
|
*/ |
|
288
|
3 |
|
public function __getJavaInternalObjectId(): int |
|
289
|
|
|
{ |
|
290
|
3 |
|
return $this->__java; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @return string |
|
295
|
|
|
*/ |
|
296
|
35 |
|
public function get__signature(): ?string |
|
297
|
|
|
{ |
|
298
|
35 |
|
return $this->__signature; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* The PHP magic method __toString() cannot be applied |
|
303
|
|
|
* on the PHP object but has to be delegated to the Java one. |
|
304
|
|
|
* |
|
305
|
|
|
* @return string |
|
306
|
|
|
*/ |
|
307
|
68 |
|
public function __toString(): string |
|
308
|
|
|
{ |
|
309
|
68 |
|
if (!isset($this->__delegate)) { |
|
310
|
|
|
$this->__createDelegate(); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
68 |
|
return $this->__delegate->__toString(); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Returns the runtime class of this Object. |
|
318
|
|
|
* The returned Class object is the object that is locked by static synchronized methods of the represented class. |
|
319
|
|
|
* |
|
320
|
|
|
* @return Interfaces\JavaObject Java('java.lang.Object') |
|
321
|
|
|
*/ |
|
322
|
1 |
|
public function getClass(): Interfaces\JavaObject |
|
323
|
|
|
{ |
|
324
|
1 |
|
return $this->__delegate->getClass(); |
|
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
|