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
|
|
|
class Arg |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var Client |
47
|
|
|
*/ |
48
|
|
|
public $client; |
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public $exception; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var SimpleFactory |
56
|
|
|
*/ |
57
|
|
|
public $factory; |
58
|
|
|
public $val; |
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
public $signature; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
public $type; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Client $client |
71
|
|
|
*/ |
72
|
43 |
|
public function __construct(Client $client) |
73
|
|
|
{ |
74
|
43 |
|
$this->client = $client; |
75
|
43 |
|
$this->factory = $client->simpleFactory; |
76
|
43 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param mixed $val |
80
|
|
|
*/ |
81
|
15 |
|
public function linkResult(&$val): void |
82
|
|
|
{ |
83
|
15 |
|
$this->val = &$val; |
84
|
15 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param mixed $val |
88
|
|
|
*/ |
89
|
113 |
|
public function setResult($val): void |
90
|
|
|
{ |
91
|
113 |
|
$this->val = &$val; |
92
|
113 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param bool $wrap |
96
|
|
|
* |
97
|
|
|
* @return JavaType|string |
98
|
|
|
*/ |
99
|
113 |
|
public function getResult(bool $wrap) |
100
|
|
|
{ |
101
|
113 |
|
$rc = $this->factory->getProxy($this->val, $this->signature, $this->exception, $wrap); |
102
|
|
|
|
103
|
113 |
|
$factory = $this->factory; |
104
|
113 |
|
$this->factory = $this->client->simpleFactory; |
105
|
113 |
|
if ($rc instanceof \Soluble\Japha\Bridge\Driver\Pjb62\Exception\JavaException) { |
106
|
22 |
|
$factory->checkResult($rc); |
107
|
|
|
} |
108
|
|
|
|
109
|
113 |
|
return $rc; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param SimpleFactory $factory |
114
|
|
|
*/ |
115
|
111 |
|
public function setFactory(SimpleFactory $factory): void |
116
|
|
|
{ |
117
|
111 |
|
$this->factory = $factory; |
118
|
111 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param string $string |
122
|
|
|
*/ |
123
|
22 |
|
public function setException(string $string): void |
124
|
|
|
{ |
125
|
22 |
|
$this->exception = $string; |
126
|
22 |
|
} |
127
|
|
|
|
128
|
|
|
public function setVoidSignature(): void |
129
|
|
|
{ |
130
|
|
|
$this->signature = '@V'; |
131
|
|
|
$key = $this->client->currentCacheKey; |
132
|
|
|
if ($key && $key[0] !== '~') { |
133
|
|
|
$this->client->currentArgumentsFormat[6] = '3'; |
134
|
|
|
$cacheEntry = new CacheEntry($this->client->currentArgumentsFormat, $this->signature, $this->factory, true); |
135
|
|
|
$this->client->methodCache[$key] = $cacheEntry; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setSignature(string $signature): void |
140
|
|
|
{ |
141
|
|
|
$this->signature = $signature; |
142
|
|
|
$key = $this->client->currentCacheKey; |
143
|
|
|
if ($key && $key[0] !== '~') { |
144
|
|
|
$cacheEntry = new CacheEntry($this->client->currentArgumentsFormat, $this->signature, $this->factory, false); |
145
|
|
|
$this->client->methodCache[$key] = $cacheEntry; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|