1 | <?php |
||
18 | class WebService implements WebServiceInterface |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * základní údaje volané při každém požadavku |
||
23 | * ID_Application, ID_Login |
||
24 | * |
||
25 | * @var array<string, mixed> |
||
26 | */ |
||
27 | protected $init; |
||
28 | |||
29 | /** |
||
30 | * @var SoapClient |
||
31 | */ |
||
32 | protected $soapClient; |
||
33 | |||
34 | /** |
||
35 | * @var EventDispatcherInterface|null |
||
36 | */ |
||
37 | private $eventDispatcher; |
||
38 | |||
39 | /** |
||
40 | * @param array<string, mixed> $soapOpts Nastaveni SOAP requestu |
||
41 | * @throws InvalidArgumentException pokud je odkaz na WSDL soubor prázdný |
||
42 | */ |
||
43 | 6 | public function __construct( |
|
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 5 | public function call(string $functionName, array $arguments = []) |
|
60 | |||
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | 5 | public function __call(string $functionName, array $arguments) |
|
69 | |||
70 | /** |
||
71 | * Metoda provadejici SOAP pozadavek na servery Skautisu |
||
72 | * |
||
73 | * @see http://php.net/manual/en/soapclient.soapcall.php |
||
74 | * |
||
75 | * @param string $functionName Nazev akce k provedeni na WebService |
||
76 | * @param array<int|string, mixed> $arguments ([0]=args [1]=cover) |
||
77 | * @param array<string, mixed> $options Nastaveni |
||
78 | * @param array<int, string> $inputHeaders Hlavicky pouzite pri odesilani |
||
79 | * @param array<int, string> $outputHeaders Hlavicky ktere prijdou s odpovedi |
||
80 | * @return array<int|string, mixed>|stdClass|null |
||
|
|||
81 | */ |
||
82 | 5 | protected function soapCall( |
|
83 | string $functionName, |
||
84 | array $arguments, |
||
85 | array $options = [], |
||
86 | array $inputHeaders = [], |
||
87 | array &$outputHeaders = [] |
||
88 | ) { |
||
89 | 5 | $fname = ucfirst($functionName); |
|
90 | 5 | $args = $this->prepareArgs($fname, $arguments); |
|
91 | |||
92 | 5 | if ($this->eventDispatcher !== null) { |
|
93 | 1 | $event = new RequestPreEvent($fname, $args, $options, $inputHeaders, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); |
|
94 | 1 | $this->eventDispatcher->dispatch($event); |
|
95 | } |
||
96 | |||
97 | 5 | $requestStart = microtime(true); |
|
98 | try { |
||
99 | 5 | $soapResponse = $this->soapClient->__soapCall($fname, $args, $options, $inputHeaders, $outputHeaders); |
|
100 | 4 | $soapResponse = $this->parseOutput($fname, $soapResponse); |
|
101 | |||
102 | 4 | if ($this->eventDispatcher !== null) { |
|
103 | $duration = microtime(true) - $requestStart; |
||
104 | $event = new RequestPostEvent($fname, $args, $soapResponse, $duration); |
||
105 | $this->eventDispatcher->dispatch($event); |
||
106 | } |
||
107 | |||
108 | 4 | return $soapResponse; |
|
109 | 1 | } catch (Throwable $t) { |
|
110 | |||
111 | 1 | if ($this->eventDispatcher !== null) { |
|
112 | 1 | $duration = microtime(true) - $requestStart; |
|
113 | 1 | $event = new RequestFailEvent($fname, $args, $t, $duration); |
|
114 | 1 | $this->eventDispatcher->dispatch($event); |
|
115 | } |
||
116 | |||
117 | 1 | throw $this->convertToSkautisException($t); |
|
118 | } |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Z defaultnich parametru a parametru callu vytvori argumenty pro SoapClient::__soapCall |
||
123 | * |
||
124 | * @param string $functionName Jmeno funkce volane pres SOAP |
||
125 | * @param array<int|string, mixed> $arguments Argumenty k mergnuti s defaultnimy |
||
126 | * |
||
127 | * @return array<int, mixed> Argumenty pro SoapClient::__soapCall |
||
128 | */ |
||
129 | 5 | protected function prepareArgs(string $functionName, array $arguments): array |
|
157 | |||
158 | /** |
||
159 | * Parsuje output ze SoapClient do jednotného formátu |
||
160 | * |
||
161 | * @param string $fname Jméno funkce volané přes SOAP |
||
162 | * @param mixed $ret Odpoveď ze SoapClient::__soapCall |
||
163 | * |
||
164 | * @return array<int|string, mixed>|\stdClass|null |
||
165 | */ |
||
166 | 4 | protected function parseOutput(string $fname, $ret) |
|
270 | |||
271 | 1 | private function convertToSkautisException(Throwable $e): WsdlException |
|
283 | } |
||
284 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.