1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Skautis; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Trida slouzici pro debugovani SOAP pozadvku na servery Skautisu |
8
|
|
|
*/ |
9
|
|
|
class SkautisQuery implements \Serializable |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string Nazev funkce volane pomoci SOAP requestu |
14
|
|
|
*/ |
15
|
|
|
public $fname; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array Parametry SOAP requestu na server |
19
|
|
|
*/ |
20
|
|
|
public $args; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array Zasobnik volanych funkci |
24
|
|
|
*/ |
25
|
|
|
public $trace; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var float Doba trvani pozadvku |
29
|
|
|
*/ |
30
|
|
|
public $time; |
31
|
|
|
|
32
|
|
|
public $result; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* V pripade ze SOAP pozadavek selze |
36
|
|
|
* |
37
|
|
|
* Nelze povolit uzivateli primy pristup kvuli serializaci. Ne vsechny exceptions jdou serializovat. |
38
|
|
|
* |
39
|
|
|
* @var \Exception|null |
40
|
|
|
*/ |
41
|
|
|
protected $exception = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Po unserializaci Query s exception je zde jeji trida |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $exceptionClass = ''; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Po unserializaci je zde text exxception |
52
|
|
|
* |
53
|
|
|
* Pouziva __toString() methodu |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $exceptionString = ''; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
* |
62
|
|
|
* @param string $fname Nazev volane funkce |
63
|
|
|
* @param array $args Argumenty pozadavku |
64
|
|
|
* @param array $trace Zasobnik volanych funkci |
65
|
|
|
*/ |
66
|
6 |
|
public function __construct( |
67
|
|
|
string $fname, |
|
|
|
|
68
|
|
|
array $args = [], |
|
|
|
|
69
|
|
|
array $trace = [] |
|
|
|
|
70
|
|
|
) { |
71
|
6 |
|
$this->fname = $fname; |
72
|
6 |
|
$this->args = $args; |
73
|
6 |
|
$this->trace = $trace; |
74
|
6 |
|
$this->time = -microtime(true); |
|
|
|
|
75
|
6 |
|
} |
76
|
|
|
|
77
|
2 |
|
public function serialize() |
78
|
|
|
{ |
79
|
|
|
$data = [ |
80
|
2 |
|
'fname' => $this->fname, |
81
|
2 |
|
'args' => $this->args, |
82
|
2 |
|
'trace' => $this->trace, |
83
|
2 |
|
'time' => $this->time, |
84
|
2 |
|
'result' => $this->result, |
85
|
2 |
|
'exception_class' => $this->exception === null ? '' : get_class($this->exception), |
86
|
2 |
|
'exception_string' => $this->exception === null ? '' : (string)$this->exception, |
87
|
|
|
]; |
88
|
2 |
|
return serialize($data); |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function unserialize($data) |
92
|
|
|
{ |
93
|
2 |
|
$data = unserialize($data); |
94
|
2 |
|
$this->fname = (string) $data['fname']; |
95
|
2 |
|
$this->args = (array) $data['args']; |
96
|
2 |
|
$this->trace = (array) $data['trace']; |
97
|
2 |
|
$this->time = (float) $data['time']; |
98
|
2 |
|
$this->result = $data['result']; |
99
|
2 |
|
$this->exceptionClass = (string) $data['exception_class']; |
100
|
2 |
|
$this->exceptionString = (string) $data['exception_string']; |
101
|
2 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Oznac pozadavek za dokonceny a uloz vysledek |
105
|
|
|
* |
106
|
|
|
* @param mixed $result Odpoved ze serveru |
107
|
|
|
* @param \Exception $e Výjimka v pripade problemu |
108
|
|
|
*/ |
109
|
6 |
|
public function done($result = null, \Exception $e = null) |
110
|
|
|
{ |
111
|
6 |
|
$this->time += microtime(true); |
112
|
6 |
|
$this->result = $result; |
113
|
6 |
|
$this->exception = $e; |
114
|
|
|
|
115
|
6 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Vrati tridu exception |
120
|
|
|
* |
121
|
|
|
* Pouziva se tato metoda protoze SoapFault exception vyhozena SoapClientem nejde serializovat |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
5 |
|
public function getExceptionClass(): string |
126
|
|
|
{ |
127
|
5 |
|
if ($this->exception === null) { |
128
|
2 |
|
return $this->exceptionClass; |
129
|
|
|
} |
130
|
|
|
|
131
|
3 |
|
return get_class($this->exception); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Vrati textovou podobu exception |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
2 |
|
public function getExceptionString(): string |
140
|
|
|
{ |
141
|
2 |
|
if ($this->exception === null) { |
142
|
|
|
return $this->exceptionString; |
143
|
|
|
} |
144
|
|
|
|
145
|
2 |
|
return (string)$this->exception; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Kontrola jestli se pozadavek zdaril |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
6 |
|
public function hasFailed(): bool |
154
|
|
|
{ |
155
|
6 |
|
return $this->exception !== null || strlen($this->exceptionClass) > 0; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|