1
- <?php declare (strict_types=1 );
2
- /**
3
- * This file is part of the CleverAge/ProcessBundle package.
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ /*
6
+ * This file is part of the CleverAge/SoapProcessBundle package.
4
7
*
5
- * Copyright (C) 2017-2019 Clever-Age
8
+ * Copyright (c) Clever-Age
6
9
*
7
10
* For the full copyright and license information, please view the LICENSE
8
11
* file that was distributed with this source code.
13
16
use Psr \Log \LoggerInterface ;
14
17
15
18
/**
16
- * Class Client
19
+ * Class Client.
17
20
*
18
21
* @author Madeline Veyrenc <[email protected] >
19
22
*/
20
23
class Client implements ClientInterface
21
24
{
22
- /** @var string */
23
- private $ code ;
24
-
25
- /** @var string|null */
26
- private $ wsdl ;
27
-
28
- /** @var array */
29
- private $ options ;
30
-
31
25
/** @var array */
32
26
private $ soapOptions ;
33
27
34
- /** @var null| \SoapHeader[] */
28
+ /** @var \SoapHeader[]|null */
35
29
private $ soapHeaders ;
36
30
37
- /** @var LoggerInterface */
38
- private $ logger ;
39
-
40
31
/** @var \SoapClient */
41
32
private $ soapClient ;
42
33
@@ -54,85 +45,54 @@ class Client implements ClientInterface
54
45
55
46
/**
56
47
* Client constructor.
57
- *
58
- * @param LoggerInterface $logger
59
- * @param string $code
60
- * @param string|null $wsdl
61
- * @param array $options
62
48
*/
63
- public function __construct (LoggerInterface $ logger , string $ code , ?string $ wsdl , array $ options )
49
+ public function __construct (private readonly LoggerInterface $ logger , private readonly string $ code , private ?string $ wsdl , private array $ options )
64
50
{
65
- $ this ->logger = $ logger ;
66
- $ this ->code = $ code ;
67
- $ this ->wsdl = $ wsdl ;
68
- $ this ->options = $ options ;
69
51
}
70
52
71
- /**
72
- * @return LoggerInterface
73
- */
74
53
public function getLogger (): LoggerInterface
75
54
{
76
55
return $ this ->logger ;
77
56
}
78
57
79
58
/**
80
- * {@inheritdoc}
81
59
* @throws \UnexpectedValueException
82
60
*/
83
61
public function getCode (): string
84
62
{
85
- if (! $ this ->code ) {
63
+ if ('' === $ this -> code || ' 0 ' === $ this ->code ) {
86
64
throw new \UnexpectedValueException ('Client code is not defined ' );
87
65
}
88
66
89
67
return $ this ->code ;
90
68
}
91
69
92
- /**
93
- * {@inheritdoc}
94
- */
95
70
public function getWsdl (): ?string
96
71
{
97
72
return $ this ->wsdl ;
98
73
}
99
74
100
- /**
101
- * {@inheritdoc}
102
- */
103
75
public function setWsdl (?string $ wsdl ): void
104
76
{
105
77
$ this ->wsdl = $ wsdl ;
106
78
}
107
79
108
- /**
109
- * {@inheritdoc}
110
- */
111
80
public function getOptions (): array
112
81
{
113
82
return $ this ->options ;
114
83
}
115
84
116
- /**
117
- * {@inheritdoc}
118
- */
119
85
public function setOptions (array $ options ): void
120
86
{
121
87
$ this ->options = $ options ;
122
88
}
123
89
124
- /**
125
- * @return array|null
126
- */
127
90
public function getSoapOptions (): ?array
128
91
{
129
92
return $ this ->soapOptions ;
130
93
}
131
94
132
- /**
133
- * @param array|null $soapOptions
134
- */
135
- public function setSoapOptions (array $ soapOptions = null ): void
95
+ public function setSoapOptions (?array $ soapOptions = null ): void
136
96
{
137
97
$ this ->soapOptions = $ soapOptions ;
138
98
}
@@ -148,127 +108,94 @@ public function getSoapHeaders(): ?array
148
108
/**
149
109
* @param \SoapHeader[]|null $soapHeaders
150
110
*/
151
- public function setSoapHeaders (array $ soapHeaders = null ): void
111
+ public function setSoapHeaders (? array $ soapHeaders = null ): void
152
112
{
153
113
$ this ->soapHeaders = $ soapHeaders ;
154
114
}
155
115
156
- /**
157
- * @return \SoapClient|null
158
- */
159
116
public function getSoapClient (): ?\SoapClient
160
117
{
161
118
return $ this ->soapClient ;
162
119
}
163
120
164
- /**
165
- * @param \SoapClient $soapClient
166
- */
167
121
public function setSoapClient (\SoapClient $ soapClient ): void
168
122
{
169
123
$ this ->soapClient = $ soapClient ;
170
124
}
171
125
172
- /**
173
- * @return string
174
- */
175
126
public function getLastRequest (): ?string
176
127
{
177
128
return $ this ->lastRequest ;
178
129
}
179
130
180
- /**
181
- * @param string $lastRequest
182
- */
183
131
public function setLastRequest (?string $ lastRequest ): void
184
132
{
185
133
$ this ->lastRequest = $ lastRequest ;
186
134
}
187
135
188
- /**
189
- * @return string
190
- */
191
136
public function getLastRequestHeaders (): ?string
192
137
{
193
138
return $ this ->lastRequestHeaders ;
194
139
}
195
140
196
- /**
197
- * @param string $lastRequestHeaders
198
- */
199
141
public function setLastRequestHeaders (?string $ lastRequestHeaders ): void
200
142
{
201
143
$ this ->lastRequestHeaders = $ lastRequestHeaders ;
202
144
}
203
145
204
- /**
205
- * @return string
206
- */
207
146
public function getLastResponse (): ?string
208
147
{
209
148
return $ this ->lastResponse ;
210
149
}
211
150
212
- /**
213
- * @param string $lastResponse
214
- */
215
151
public function setLastResponse (?string $ lastResponse ): void
216
152
{
217
153
$ this ->lastResponse = $ lastResponse ;
218
154
}
219
155
220
- /**
221
- * @return string
222
- */
223
156
public function getLastResponseHeaders (): ?string
224
157
{
225
158
return $ this ->lastResponseHeaders ;
226
159
}
227
160
228
- /**
229
- * @param string $lastResponseHeaders
230
- */
231
161
public function setLastResponseHeaders (?string $ lastResponseHeaders ): void
232
162
{
233
163
$ this ->lastResponseHeaders = $ lastResponseHeaders ;
234
164
}
235
165
236
166
/**
237
- * {@inheritdoc}
167
+ * @return bool|mixed
238
168
*/
239
- public function call (string $ method , array $ input = [])
169
+ public function call (string $ method , array $ input = []): mixed
240
170
{
241
171
$ this ->initializeSoapClient ();
242
172
243
- $ callMethod = sprintf ('soapCall%s ' , ucfirst ($ method ));
173
+ $ callMethod = \ sprintf ('soapCall%s ' , ucfirst ($ method ));
244
174
if (method_exists ($ this , $ callMethod )) {
245
175
return $ this ->$ callMethod ($ input );
246
176
}
247
177
248
178
$ this ->getLogger ()->notice (
249
- sprintf ("Soap call '%s' on '%s' " , $ method , $ this ->getWsdl ())
179
+ \ sprintf ("Soap call '%s' on '%s' " , $ method , $ this ->getWsdl ())
250
180
);
251
181
252
182
return $ this ->doSoapCall ($ method , $ input );
253
183
}
254
184
255
185
/**
256
- * @param string $method
257
- * @param array $input
258
- *
259
186
* @return bool|mixed
260
187
*/
261
- protected function doSoapCall (string $ method , array $ input = [])
188
+ protected function doSoapCall (string $ method , array $ input = []): mixed
262
189
{
263
- if (!$ this ->getSoapClient ()) {
190
+ if (!$ this ->getSoapClient () instanceof \SoapClient ) {
264
191
throw new \InvalidArgumentException ('Soap client is not initialized ' );
265
192
}
266
193
try {
267
194
$ result = $ this ->getSoapClient ()->__soapCall ($ method , $ input , $ this ->getSoapOptions (), $ this ->getSoapHeaders ());
268
- } /** @noinspection PhpRedundantCatchClauseInspection */ catch (\SoapFault $ e ) {
195
+ } /* @noinspection PhpRedundantCatchClauseInspection */ catch (\SoapFault $ e ) {
269
196
$ this ->getLastRequestTrace ();
270
197
$ this ->getLogger ()->alert (
271
- sprintf ("Soap call '%s' on '%s' failed : %s " , $ method , $ this ->getWsdl (), $ e ->getMessage ()),
198
+ \ sprintf ("Soap call '%s' on '%s' failed : %s " , $ method , $ this ->getWsdl (), $ e ->getMessage ()),
272
199
$ this ->getLastRequestTraceArray ()
273
200
);
274
201
@@ -277,9 +204,9 @@ protected function doSoapCall(string $method, array $input = [])
277
204
278
205
$ this ->getLastRequestTrace ();
279
206
280
- if (array_key_exists ('trace ' , $ this ->getOptions ()) && $ this ->getOptions ()['trace ' ]) {
207
+ if (\ array_key_exists ('trace ' , $ this ->getOptions ()) && $ this ->getOptions ()['trace ' ]) {
281
208
$ this ->getLogger ()->debug (
282
- sprintf ("Trace of soap call '%s' on '%s' " , $ method , $ this ->getWsdl ()),
209
+ \ sprintf ("Trace of soap call '%s' on '%s' " , $ method , $ this ->getWsdl ()),
283
210
$ this ->getLastRequestTraceArray ()
284
211
);
285
212
}
@@ -288,33 +215,26 @@ protected function doSoapCall(string $method, array $input = [])
288
215
}
289
216
290
217
/**
291
- * Initialize \SoapClient object
292
- *
293
- * @return void
218
+ * Initialize \SoapClient object.
294
219
*/
295
220
protected function initializeSoapClient (): void
296
221
{
297
- if (!$ this ->getSoapClient ()) {
222
+ if (!$ this ->getSoapClient () instanceof \SoapClient ) {
298
223
$ options = array_merge ($ this ->getOptions (), ['trace ' => true ]);
299
224
$ this ->setSoapClient (new \SoapClient ($ this ->getWsdl (), $ options ));
300
225
}
301
226
}
302
227
303
- /**
304
- */
305
228
protected function getLastRequestTrace (): void
306
229
{
307
- if ($ this ->getSoapClient ()) {
230
+ if ($ this ->getSoapClient () instanceof \SoapClient ) {
308
231
$ this ->setLastRequest ($ this ->getSoapClient ()->__getLastRequest ());
309
232
$ this ->setLastRequestHeaders ($ this ->getSoapClient ()->__getLastRequestHeaders ());
310
233
$ this ->setLastResponse ($ this ->getSoapClient ()->__getLastResponse ());
311
234
$ this ->setLastResponseHeaders ($ this ->getSoapClient ()->__getLastResponseHeaders ());
312
235
}
313
236
}
314
237
315
- /**
316
- * @return array
317
- */
318
238
protected function getLastRequestTraceArray (): array
319
239
{
320
240
return [
0 commit comments