|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Soluble Japha / PhpJavaBridge. |
|
5
|
|
|
* |
|
6
|
|
|
* Compatibility function to work with previous |
|
7
|
|
|
* version og PhpJavaBridge |
|
8
|
|
|
* |
|
9
|
|
|
* @author Vanvelthem Sébastien |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
use Soluble\Japha\Bridge\Driver\Pjb62; |
|
13
|
|
|
use Soluble\Japha\Bridge\Driver\Pjb62\Exception; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Kept for compatibilty purpose. |
|
17
|
|
|
*/ |
|
18
|
|
|
class Java extends Soluble\Japha\Bridge\Driver\Pjb62\Java |
|
19
|
|
|
{ |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Kept for compatibilty purpose. |
|
24
|
|
|
*/ |
|
25
|
|
|
class java_class extends Soluble\Japha\Bridge\Driver\Pjb62\JavaClass |
|
26
|
|
|
{ |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Kept for compatibilty purpose. |
|
31
|
|
|
*/ |
|
32
|
|
|
class JavaClass extends java_class |
|
33
|
|
|
{ |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Kept for compatibilty purpose. |
|
38
|
|
|
* |
|
39
|
|
|
* @return Client |
|
40
|
|
|
*/ |
|
41
|
|
|
function __javaproxy_Client_getClient() |
|
42
|
|
|
{ |
|
43
|
|
|
return Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @deprecated |
|
48
|
|
|
* |
|
49
|
|
|
* @param mixed $x |
|
50
|
|
|
* |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
|
|
function java_autoload_function5($x) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
// do nothing compser autoload instead |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @deprecated |
|
60
|
|
|
* |
|
61
|
|
|
* @param mixed $x |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
function java_autoload_function($x) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
// do nothing composer autoload instead |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Return a Java class. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name Name of the java class |
|
74
|
|
|
* |
|
75
|
|
|
* @return Pjb62\JavaClass |
|
76
|
|
|
*/ |
|
77
|
|
|
function java_class($name) |
|
78
|
|
|
{ |
|
79
|
2 |
|
return Pjb62\PjbProxyClient::getInstance()->getJavaClass($name); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Invoke a method dynamically. |
|
84
|
|
|
|
|
85
|
|
|
* Example: |
|
86
|
|
|
* <code> |
|
87
|
|
|
* java_invoke(new java("java.lang.String","hello"), "toString", array()) |
|
88
|
|
|
* </code> |
|
89
|
|
|
* |
|
90
|
|
|
* <br> Any declared exception can be caught by PHP code. <br> |
|
91
|
|
|
* Exceptions derived from java.lang.RuntimeException or Error should |
|
92
|
|
|
* not be caught unless declared in the methods throws clause -- OutOfMemoryErrors cannot be caught at all, |
|
93
|
|
|
* even if declared. |
|
94
|
|
|
* |
|
95
|
|
|
* @param Pjb62\JavaType $object A java object or type |
|
96
|
|
|
* @param string $method A method string |
|
97
|
|
|
* @param array $args An argument array |
|
98
|
|
|
*/ |
|
99
|
|
|
function java_invoke($object, $method, $args) |
|
100
|
|
|
{ |
|
101
|
|
|
Pjb62\PjbProxyClient::getInstance()->invokeMethod($object, $method, $args); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param Pjb62\Client $client |
|
106
|
|
|
* |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
function java_getCompatibilityOption($client) |
|
110
|
|
|
{ |
|
111
|
|
|
return Pjb62\PjbProxyClient::getInstance()->getCompatibilityOption($client); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param Pjb62\JavaType $ob |
|
116
|
|
|
* @param Pjb62\JavaType $clazz |
|
117
|
|
|
* |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
|
|
function java_instanceof_internal(Pjb62\JavaType $ob, Pjb62\JavaType $clazz) |
|
121
|
|
|
{ |
|
122
|
|
|
return Pjb62\PjbProxyClient::getInstance()->isInstanceOf($ob, $clazz); |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param Pjb62\JavaType $ob |
|
127
|
|
|
* @param Pjb62\JavaType $clazz |
|
128
|
|
|
* |
|
129
|
|
|
* @return bool |
|
130
|
|
|
* |
|
131
|
|
|
* @throws Exception\IllegalArgumentException |
|
132
|
|
|
*/ |
|
133
|
|
|
function java_instanceof($ob, $clazz) |
|
134
|
|
|
{ |
|
135
|
1 |
|
return Pjb62\PjbProxyClient::getInstance()->isInstanceOf($ob, $clazz); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Evaluate a Java object. |
|
140
|
|
|
* |
|
141
|
|
|
* Evaluate a object and fetch its content, if possible. Use java_values() to convert a Java object into an equivalent PHP value. |
|
142
|
|
|
* |
|
143
|
|
|
* A java array, Map or Collection object is returned |
|
144
|
|
|
* as a php array. An array, Map or Collection proxy is returned as a java array, Map or Collection object, and a null proxy is returned as null. All values of java types for which a primitive php type exists are returned as php values. Everything else is returned unevaluated. Please make sure that the values do not not exceed |
|
145
|
|
|
* php's memory limit. Example: |
|
146
|
|
|
* |
|
147
|
|
|
* |
|
148
|
|
|
* <code> |
|
149
|
|
|
* $str = new java("java.lang.String", "hello"); |
|
150
|
|
|
* echo java_values($str); |
|
151
|
|
|
* => hello |
|
152
|
|
|
* $chr = $str->toCharArray(); |
|
153
|
|
|
* echo $chr; |
|
154
|
|
|
* => [o(array_of-C):"[C@1b10d42"] |
|
155
|
|
|
* $ar = java_values($chr); |
|
156
|
|
|
* print $ar; |
|
157
|
|
|
* => Array |
|
158
|
|
|
* print $ar[0]; |
|
159
|
|
|
* => [o(Character):"h"] |
|
160
|
|
|
* print java_values($ar[0]); |
|
161
|
|
|
* => h |
|
162
|
|
|
* </code> |
|
163
|
|
|
* |
|
164
|
|
|
* @param Pjb62\JavaType|null $object |
|
165
|
|
|
* |
|
166
|
|
|
* @return mixed |
|
167
|
|
|
*/ |
|
168
|
|
|
function java_values($object) |
|
169
|
|
|
{ |
|
170
|
3 |
|
if ($object === null || !$object instanceof Pjb62\JavaType) { |
|
171
|
2 |
|
return $object; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
3 |
|
return Pjb62\PjbProxyClient::getInstance()->getValues($object); |
|
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param Pjb62\JavaType $object |
|
179
|
|
|
*/ |
|
180
|
|
|
function java_values_internal($object) |
|
181
|
|
|
{ |
|
182
|
|
|
return Pjb62\PjbProxyClient::getInstance()->getValues($object); |
|
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param Pjb62\JavaType $object |
|
187
|
|
|
* |
|
188
|
|
|
* @return string |
|
189
|
|
|
*/ |
|
190
|
|
|
function java_inspect_internal(Pjb62\JavaType $object) |
|
191
|
|
|
{ |
|
192
|
|
|
//$client = __javaproxy_Client_getClient(); |
|
193
|
|
|
//return $client->invokeMethod(0, "inspect", array($object)); |
|
194
|
|
|
return Pjb62\PjbProxyClient::getInstance()->inspect($object); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param Pjb62\JavaType $object |
|
199
|
|
|
* |
|
200
|
|
|
* @return string |
|
201
|
|
|
* |
|
202
|
|
|
* @throws Exception\IllegalArgumentException |
|
203
|
|
|
*/ |
|
204
|
|
|
function java_inspect(Pjb62\JavaType $object) |
|
205
|
|
|
{ |
|
206
|
1 |
|
return Pjb62\PjbProxyClient::getInstance()->inspect($object); |
|
207
|
|
|
//return java_inspect_internal($object); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
function java_last_exception_get() |
|
211
|
|
|
{ |
|
212
|
|
|
return Pjb62\PjbProxyClient::getInstance()->getLastException(); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
function java_last_exception_clear() |
|
216
|
|
|
{ |
|
217
|
|
|
return Pjb62\PjbProxyClient::getInstance()->clearLastException(); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return string |
|
222
|
|
|
*/ |
|
223
|
|
|
function java_get_base() |
|
224
|
|
|
{ |
|
225
|
|
|
throw new \Exception('java_get_base has not been ported to new specs'); |
|
226
|
|
|
/* |
|
227
|
|
|
$ar = get_required_files(); |
|
228
|
|
|
$arLen = sizeof($ar); |
|
229
|
|
|
if ($arLen > 0) { |
|
230
|
|
|
$thiz = $ar[$arLen - 1]; |
|
231
|
|
|
return dirname($thiz); |
|
232
|
|
|
} else { |
|
233
|
|
|
return "java"; |
|
234
|
|
|
} |
|
235
|
|
|
*/ |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
function java_defineHostFromInitialQuery($java_base) |
|
|
|
|
|
|
239
|
|
|
{ |
|
240
|
|
|
throw new \Exception('java_defineHostFromInitialQuery has not been ported to new specs'); |
|
241
|
|
|
/* |
|
242
|
|
|
if ($java_base != "java") { |
|
243
|
|
|
$url = parse_url($java_base); |
|
244
|
|
|
if (isset($url["scheme"]) && ($url["scheme"] == "http" || $url["scheme"] == "https")) { |
|
245
|
|
|
$scheme = $url["scheme"] == "https" ? "ssl://" : ""; |
|
246
|
|
|
$host = $url["host"]; |
|
247
|
|
|
$port = $url["port"]; |
|
248
|
|
|
$path = $url["path"]; |
|
249
|
|
|
define("JAVA_HOSTS", "${scheme}${host}:${port}"); |
|
250
|
|
|
$dir = dirname($path); |
|
251
|
|
|
define("JAVA_SERVLET", "$dir/servlet.phpjavabridge"); |
|
252
|
|
|
return true; |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
return false; |
|
256
|
|
|
*/ |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
function java_truncate($str) |
|
260
|
|
|
{ |
|
261
|
|
|
if (strlen($str) > 955) { |
|
262
|
|
|
return substr($str, 0, 475) . '[...]' . substr($str, -475); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
return $str; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
function java_virtual($path, $return = false) |
|
269
|
|
|
{ |
|
270
|
|
|
$req = java_context()->getHttpServletRequest(); |
|
271
|
|
|
$req = new Java('php.java.servlet.VoidInputHttpServletRequest', $req); |
|
272
|
|
|
$res = java_context()->getHttpServletResponse(); |
|
273
|
|
|
$res = new Java('php.java.servlet.RemoteHttpServletResponse', $res); |
|
274
|
|
|
$req->getRequestDispatcher($path)->include($req, $res); |
|
|
|
|
|
|
275
|
|
|
if ($return) { |
|
276
|
|
|
return $res->getBufferContents(); |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
echo $res->getBufferContents(); |
|
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
return true; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
function java_get_closure() |
|
284
|
|
|
{ |
|
285
|
|
|
return java_closure_array(func_get_args()); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
function java_wrap() |
|
289
|
|
|
{ |
|
290
|
|
|
return java_closure_array(func_get_args()); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
function java_get_values($arg) |
|
294
|
|
|
{ |
|
295
|
1 |
|
return java_values($arg); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
function java_get_session() |
|
299
|
|
|
{ |
|
300
|
|
|
return java_session_array(func_get_args()); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
function java_get_context() |
|
304
|
|
|
{ |
|
305
|
|
|
return java_context(); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
function java_get_server_name() |
|
309
|
|
|
{ |
|
310
|
|
|
return java_server_name(); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Test whether a java object value is null. |
|
315
|
|
|
* |
|
316
|
|
|
* @param Pjb62\JavaType|null $value |
|
317
|
|
|
* |
|
318
|
|
|
* @return bool |
|
319
|
|
|
*/ |
|
320
|
|
|
function java_isnull($value) |
|
321
|
|
|
{ |
|
322
|
1 |
|
return java_is_null($value); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* Test whether a java object value is null. |
|
327
|
|
|
* |
|
328
|
|
|
* @param Pjb62\JavaType|null $value |
|
329
|
|
|
* |
|
330
|
|
|
* @return bool |
|
331
|
|
|
*/ |
|
332
|
|
|
function java_is_null($value) |
|
333
|
|
|
{ |
|
334
|
1 |
|
return is_null(java_values($value)); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* Test whether a java object value is true. |
|
339
|
|
|
* |
|
340
|
|
|
* @param Pjb62\JavaType|null $value |
|
341
|
|
|
* |
|
342
|
|
|
* @return bool |
|
343
|
|
|
*/ |
|
344
|
|
|
function java_istrue($value) |
|
345
|
|
|
{ |
|
346
|
1 |
|
return java_is_true($value); |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* Test whether a java object value is null. |
|
351
|
|
|
* |
|
352
|
|
|
* @param Pjb62\JavaType|null $value |
|
353
|
|
|
* |
|
354
|
|
|
* @return bool |
|
355
|
|
|
*/ |
|
356
|
|
|
function java_is_true($value) |
|
357
|
|
|
{ |
|
358
|
1 |
|
return (bool) (java_values($value)); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* Test whether a java object value is false. |
|
363
|
|
|
* |
|
364
|
|
|
* @param Pjb62\JavaType|null $value |
|
365
|
|
|
* |
|
366
|
|
|
* @return bool |
|
367
|
|
|
*/ |
|
368
|
|
|
function java_isfalse($value) |
|
369
|
|
|
{ |
|
370
|
1 |
|
return java_is_false($value); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* Test whether a java object value is false. |
|
375
|
|
|
* |
|
376
|
|
|
* Warning: originally this method contained a long standing issue: an empty string |
|
377
|
|
|
* is considered as false. To not break compatibility it's remaining like this |
|
378
|
|
|
* |
|
379
|
|
|
* @param Pjb62\JavaType|null $value |
|
380
|
|
|
* |
|
381
|
|
|
* @return bool |
|
382
|
|
|
*/ |
|
383
|
|
|
function java_is_false($value) |
|
384
|
|
|
{ |
|
385
|
1 |
|
return !(java_values($value)); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
function java_call_with_continuation($kontinuation = null) |
|
|
|
|
|
|
389
|
|
|
{ |
|
390
|
|
|
if (java_getHeader('X_JAVABRIDGE_INCLUDE', $_SERVER) && !java_getHeader('X_JAVABRIDGE_INCLUDE_ONLY', $_SERVER)) { |
|
391
|
|
|
if (is_null($kontinuation)) { |
|
392
|
|
|
java_context()->call(java_closure()); |
|
393
|
|
|
} elseif (is_string($kontinuation)) { |
|
394
|
|
|
java_context()->call(call_user_func($kontinuation)); |
|
395
|
|
|
} elseif ($kontinuation instanceof Pjb62\JavaType) { |
|
396
|
|
|
java_context()->call($kontinuation); |
|
397
|
|
|
} else { |
|
398
|
|
|
java_context()->call(java_closure($kontinuation)); |
|
399
|
|
|
} |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* Return java bridge header. |
|
405
|
|
|
* |
|
406
|
|
|
* @param $name header name |
|
407
|
|
|
* @param array $array |
|
408
|
|
|
* |
|
409
|
|
|
* @return string|void |
|
410
|
|
|
*/ |
|
411
|
|
|
function java_getHeader($name, array $array) |
|
412
|
|
|
{ |
|
413
|
|
|
return Pjb62\Pjb62Driver::getJavaBridgeHeader($name, $array); |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
function java_checkCliSapi() |
|
417
|
|
|
{ |
|
418
|
|
|
$sapi = substr(php_sapi_name(), 0, 3); |
|
419
|
|
|
|
|
420
|
|
|
return (($sapi == 'cgi') && !get_cfg_var('java.session')) || ($sapi == 'cli'); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
/** |
|
424
|
|
|
* Unwrap a Java object. |
|
425
|
|
|
* |
|
426
|
|
|
* Fetches the PHP object which has been wrapped by java_closure(). Example: |
|
427
|
|
|
* <code> |
|
428
|
|
|
* class foo { function __toString() {return "php"; } function toString() {return "java";} } |
|
429
|
|
|
* $foo = java_closure(new foo()); |
|
430
|
|
|
* echo $foo; |
|
431
|
|
|
* => java; |
|
432
|
|
|
* $foo = java_unwrap($foo); |
|
433
|
|
|
* echo $foo; |
|
434
|
|
|
* => php |
|
435
|
|
|
* </code> |
|
436
|
|
|
* |
|
437
|
|
|
* @param Pjb62\JavaType $object |
|
438
|
|
|
*/ |
|
439
|
|
|
function java_unwrap(Pjb62\JavaType $object) |
|
440
|
|
|
{ |
|
441
|
|
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
442
|
|
|
|
|
443
|
|
|
return $client->globalRef->get($client->invokeMethod(0, 'unwrapClosure', [$object])); |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
/** |
|
447
|
|
|
* @param string $enc encoding |
|
448
|
|
|
*/ |
|
449
|
|
|
function java_set_encoding($enc) |
|
450
|
|
|
{ |
|
451
|
|
|
return java_set_file_encoding($enc); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
/** |
|
455
|
|
|
* @param string $enc encoding |
|
456
|
|
|
*/ |
|
457
|
|
|
function java_set_file_encoding($enc) |
|
458
|
|
|
{ |
|
459
|
1 |
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
460
|
|
|
|
|
461
|
1 |
|
return $client->invokeMethod(0, 'setFileEncoding', [$enc]); |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* @param Pjb62\JavaType $object |
|
466
|
|
|
* @param string $type |
|
467
|
|
|
* |
|
468
|
|
|
* @return Pjb62\JavaType |
|
469
|
|
|
*/ |
|
470
|
|
|
function java_cast_internal($object, $type) |
|
471
|
|
|
{ |
|
472
|
2 |
|
return Pjb62\Pjb62Driver::castPjbInternal($object, $type); |
|
|
|
|
|
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* @param Pjb62\JavaType $object |
|
477
|
|
|
* @param string $type |
|
478
|
|
|
* |
|
479
|
|
|
* @return Pjb62\JavaType |
|
480
|
|
|
*/ |
|
481
|
|
|
function java_cast($object, $type) |
|
482
|
|
|
{ |
|
483
|
2 |
|
return java_cast_internal($object, $type); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
function java_get_lifetime() |
|
487
|
|
|
{ |
|
488
|
|
|
$session_max_lifetime = ini_get('session.gc_maxlifetime'); |
|
489
|
|
|
|
|
490
|
|
|
return $session_max_lifetime ? (int) $session_max_lifetime : 1440; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
function java_session_array($args) |
|
494
|
|
|
{ |
|
495
|
|
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
496
|
|
|
if (!isset($args[0])) { |
|
497
|
|
|
$args[0] = null; |
|
498
|
|
|
} |
|
499
|
|
|
if (!isset($args[1])) { |
|
500
|
|
|
$args[1] = 0; |
|
501
|
|
|
} elseif ($args[1] === true) { |
|
502
|
|
|
$args[1] = 1; |
|
503
|
|
|
} else { |
|
504
|
|
|
$args[1] = 2; |
|
505
|
|
|
} |
|
506
|
|
|
if (!isset($args[2])) { |
|
507
|
|
|
$args[2] = java_get_lifetime(); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
return $client->getSession($args); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
function java_session() |
|
514
|
|
|
{ |
|
515
|
|
|
return java_session_array(func_get_args()); |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
/** |
|
519
|
|
|
* @return string|null |
|
520
|
|
|
*/ |
|
521
|
|
|
function java_server_name() |
|
522
|
|
|
{ |
|
523
|
|
|
try { |
|
524
|
1 |
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
525
|
|
|
|
|
526
|
1 |
|
return $client->getServerName(); |
|
527
|
|
|
} catch (Exception\ConnectException $ex) { |
|
528
|
|
|
return; |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
function java_context() |
|
533
|
|
|
{ |
|
534
|
1 |
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
535
|
|
|
|
|
536
|
1 |
|
return $client->getContext(); |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
function java_closure_array($args) |
|
540
|
|
|
{ |
|
541
|
|
|
if (isset($args[2]) && ((!($args[2] instanceof Pjb62\JavaType)) && !is_array($args[2]))) { |
|
542
|
|
|
throw new Exception\IllegalArgumentException($args[2]); |
|
543
|
|
|
} |
|
544
|
|
|
$client = Pjb62\PjbProxyClient::getInstance()->getClient(); |
|
545
|
|
|
$args[0] = isset($args[0]) ? $client->globalRef->add($args[0]) : 0; |
|
546
|
|
|
$client->protocol->invokeBegin(0, 'makeClosure'); |
|
547
|
|
|
$n = count($args); |
|
548
|
|
|
$client->protocol->writeULong($args[0]); |
|
549
|
|
|
for ($i = 1; $i < $n; ++$i) { |
|
550
|
|
|
$client->writeArg($args[$i]); |
|
551
|
|
|
} |
|
552
|
|
|
$client->protocol->invokeEnd(); |
|
553
|
|
|
$val = $client->getResult(); |
|
554
|
|
|
|
|
555
|
|
|
return $val; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
function java_closure() |
|
559
|
|
|
{ |
|
560
|
|
|
return java_closure_array(func_get_args()); |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
/* |
|
564
|
|
|
* Can be removed |
|
565
|
|
|
* |
|
566
|
|
|
*/ |
|
567
|
|
|
/* |
|
568
|
|
|
* |
|
569
|
|
|
function java_require($arg) |
|
570
|
|
|
{ |
|
571
|
|
|
trigger_error('java_require() not supported anymore. Please use <a href="http://php-java-bridge.sourceforge.net/pjb/webapp.php>tomcat or jee hot deployment</a> instead', E_USER_WARNING); |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
function java_autoload($libs = null) |
|
575
|
|
|
{ |
|
576
|
|
|
trigger_error('Please use <a href="http://php-java-bridge.sourceforge.net/pjb/webapp.php>tomcat or jee hot deployment</a> instead', E_USER_WARNING); |
|
577
|
|
|
} |
|
578
|
|
|
function java_begin_document() |
|
579
|
|
|
{ |
|
580
|
|
|
} |
|
581
|
|
|
|
|
582
|
|
|
function java_end_document() |
|
583
|
|
|
{ |
|
584
|
|
|
} |
|
585
|
|
|
function bootstrap() |
|
586
|
|
|
{ |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
|
|
590
|
|
|
*/ |
|
591
|
|
|
|
|
592
|
|
|
// REFACTORED METHODS |
|
593
|
|
|
/* |
|
594
|
|
|
function __javaproxy_Client_getClient2() |
|
595
|
|
|
{ |
|
596
|
|
|
static $client = null; |
|
597
|
|
|
Soluble\Japha\Bridge\Driver\Pjb62::$client; |
|
598
|
|
|
if (!is_null($client)) { |
|
599
|
|
|
return $client; |
|
600
|
|
|
} |
|
601
|
|
|
if (function_exists("java_create_client")) { |
|
602
|
|
|
$client = java_create_client(); |
|
603
|
|
|
} else { |
|
604
|
|
|
global $java_initialized; |
|
605
|
|
|
$client = new Client(); |
|
606
|
|
|
|
|
607
|
|
|
$client->throwExceptionProxyFactory = |
|
608
|
|
|
new Adapter\DefaultThrowExceptionProxyFactory($client); |
|
609
|
|
|
|
|
610
|
|
|
$java_initialized = true; |
|
611
|
|
|
} |
|
612
|
|
|
return $client; |
|
613
|
|
|
} |
|
614
|
|
|
*/ |
|
615
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: