1 | <?php |
||
12 | class SoapFaultProcessor |
||
13 | { |
||
14 | /** |
||
15 | * An exception thrown by \SoapCall. |
||
16 | * |
||
17 | * @var \SoapFault |
||
18 | */ |
||
19 | private $exception; |
||
20 | /** |
||
21 | * Messages collected during processing. |
||
22 | * |
||
23 | * @var string[] |
||
24 | */ |
||
25 | private $errors = []; |
||
26 | /** |
||
27 | * Expected error code. |
||
28 | * |
||
29 | * @var null|string |
||
30 | */ |
||
31 | private $code; |
||
32 | /** |
||
33 | * Expected error message. |
||
34 | * |
||
35 | * @var null|string |
||
36 | */ |
||
37 | private $message; |
||
38 | /** |
||
39 | * Condition between comparison of error code and message. |
||
40 | * |
||
41 | * @var null|string |
||
42 | */ |
||
43 | private $condition; |
||
44 | |||
45 | /** |
||
46 | * SoapFaultProcessor constructor. |
||
47 | * |
||
48 | * @param \SoapFault $exception |
||
49 | * @param null|string $code |
||
50 | * Any numeric value. Type will be casted to "int". |
||
51 | * @param null|string $message |
||
52 | * Expected message. Inaccurate matching will be used. |
||
53 | * @param null|string $condition |
||
54 | * Allowed values: "or", "and". |
||
55 | */ |
||
56 | public function __construct(\SoapFault $exception, $code = null, $message = null, $condition = null) |
||
63 | |||
64 | /** |
||
65 | * Process the data. |
||
66 | */ |
||
67 | public function __destruct() |
||
68 | { |
||
69 | $this->processCode() |
||
70 | ->processMessage() |
||
71 | ->processCondition(); |
||
72 | |||
73 | if (!empty($this->errors)) { |
||
74 | throw new \RuntimeException(implode("\n", $this->errors)); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Process expected exit code. |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | private function processCode() |
||
95 | |||
96 | /** |
||
97 | * Process expected error message. |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | private function processMessage() |
||
113 | |||
114 | /** |
||
115 | * Filter messages depending on condition. |
||
116 | */ |
||
117 | private function processCondition() |
||
129 | } |
||
130 |