|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Soluble Japha |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://github.com/belgattitude/soluble-japha |
|
9
|
|
|
* @copyright Copyright (c) 2013-2020 Vanvelthem Sébastien |
|
10
|
|
|
* @license MIT License https://github.com/belgattitude/soluble-japha/blob/master/LICENSE.md |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Soluble\Japha\Bridge\Exception; |
|
14
|
|
|
|
|
15
|
|
|
use Exception; |
|
16
|
|
|
|
|
17
|
|
|
class JavaException extends Exception implements JavaExceptionInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $javaClassName; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $cause; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $stackTrace; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var Exception |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $driverException; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $message |
|
43
|
|
|
* @param string $javaCause |
|
44
|
|
|
* @param string $stackTrace |
|
45
|
|
|
* @param string $javaClassName originating java FQCN |
|
46
|
|
|
* @param int $code |
|
47
|
|
|
* @param Exception $driverException |
|
48
|
|
|
* @param Exception $previous |
|
49
|
|
|
*/ |
|
50
|
22 |
|
public function __construct( |
|
51
|
|
|
$message, |
|
52
|
|
|
$javaCause, |
|
53
|
|
|
$stackTrace, |
|
54
|
|
|
$javaClassName, |
|
55
|
|
|
$code = null, |
|
56
|
|
|
Exception $driverException = null, |
|
57
|
|
|
Exception $previous = null |
|
58
|
|
|
) { |
|
59
|
22 |
|
parent::__construct($message, $code, $previous); |
|
60
|
22 |
|
$this->setCause($javaCause); |
|
61
|
22 |
|
$this->setStackTrace($stackTrace); |
|
62
|
22 |
|
$this->setJavaClassName($javaClassName); |
|
63
|
22 |
|
if ($driverException !== null) { |
|
64
|
22 |
|
$this->setDriverException($driverException); |
|
65
|
|
|
} |
|
66
|
22 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set original exception as throw by the driver. |
|
70
|
|
|
* |
|
71
|
|
|
* @param Exception $driverException |
|
72
|
|
|
*/ |
|
73
|
22 |
|
private function setDriverException(Exception $driverException): void |
|
74
|
|
|
{ |
|
75
|
22 |
|
$this->driverException = $driverException; |
|
76
|
22 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Return underlying driver exception. |
|
80
|
|
|
* |
|
81
|
|
|
* @return Exception|null |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getDriverException(): ?Exception |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->driverException; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Set Java cause. |
|
90
|
|
|
*/ |
|
91
|
22 |
|
private function setCause(string $cause): void |
|
92
|
|
|
{ |
|
93
|
22 |
|
$this->cause = $cause; |
|
94
|
22 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getCause(): string |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->cause; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Set JVM Stack trace. |
|
106
|
|
|
*/ |
|
107
|
22 |
|
private function setStackTrace(string $stackTrace): void |
|
108
|
|
|
{ |
|
109
|
22 |
|
$this->stackTrace = $stackTrace; |
|
110
|
22 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritdoc} |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function getStackTrace(): string |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->stackTrace; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
2 |
|
public function getJavaClassName(): string |
|
124
|
|
|
{ |
|
125
|
2 |
|
return $this->javaClassName; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Set java exception class name. |
|
130
|
|
|
*/ |
|
131
|
22 |
|
private function setJavaClassName(string $javaClassName): void |
|
132
|
|
|
{ |
|
133
|
22 |
|
$this->javaClassName = $javaClassName; |
|
134
|
22 |
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|