1 | <?php |
||||
2 | App::uses('DataSource', 'Model/Datasource'); |
||||
3 | |||||
4 | /** |
||||
5 | * SOAP DataSource. |
||||
6 | * |
||||
7 | */ |
||||
8 | class SoapSource extends DataSource { |
||||
0 ignored issues
–
show
|
|||||
9 | |||||
10 | /** |
||||
11 | * Description. |
||||
12 | * |
||||
13 | * @var string |
||||
14 | */ |
||||
15 | public $description = 'Soap Client DataSource'; |
||||
16 | |||||
17 | /** |
||||
18 | * SoapClient instance. |
||||
19 | * |
||||
20 | * @var SoapClient|null |
||||
21 | */ |
||||
22 | public $client = null; |
||||
23 | |||||
24 | /** |
||||
25 | * Connection status. |
||||
26 | * |
||||
27 | * @var bool |
||||
28 | */ |
||||
29 | public $connected = false; |
||||
30 | |||||
31 | /** |
||||
32 | * Default configuration. |
||||
33 | * |
||||
34 | * @var array |
||||
35 | */ |
||||
36 | protected $_baseConfig = [ |
||||
37 | 'wsdl' => null, |
||||
38 | 'location' => '', |
||||
39 | 'uri' => '', |
||||
40 | 'login' => '', |
||||
41 | 'password' => '', |
||||
42 | 'authentication' => 'SOAP_AUTHENTICATION_BASIC' |
||||
43 | ]; |
||||
44 | |||||
45 | /** |
||||
46 | * Constructor. |
||||
47 | * |
||||
48 | * @param array $config An array defining the configuration settings |
||||
49 | */ |
||||
50 | public function __construct($config = []) { |
||||
51 | parent::__construct($config); |
||||
52 | |||||
53 | $this->connected = $this->connect(); |
||||
54 | } |
||||
55 | |||||
56 | /** |
||||
57 | * Setup Configuration options. |
||||
58 | * |
||||
59 | * @return array|bool Configuration options or false on failure |
||||
60 | */ |
||||
61 | protected function _parseConfig() { |
||||
62 | if (!class_exists('SoapClient')) { |
||||
63 | $this->showError('Class SoapClient not found, please enable Soap extensions'); |
||||
64 | return false; |
||||
65 | } |
||||
66 | |||||
67 | $options = ['trace' => Configure::read('debug') > 0]; |
||||
0 ignored issues
–
show
The type
Configure was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
68 | if (!empty($this->config['location'])) { |
||||
69 | $options['location'] = $this->config['location']; |
||||
70 | } |
||||
71 | |||||
72 | if (!empty($this->config['uri'])) { |
||||
73 | $options['uri'] = $this->config['uri']; |
||||
74 | } |
||||
75 | |||||
76 | if (!empty($this->config['login'])) { |
||||
77 | $options['login'] = $this->config['login']; |
||||
78 | $options['password'] = $this->config['password']; |
||||
79 | $options['authentication'] = $this->config['authentication']; |
||||
80 | } |
||||
81 | |||||
82 | return $options; |
||||
83 | } |
||||
84 | |||||
85 | /** |
||||
86 | * Connects to the SOAP server using the WSDL in the configuration. |
||||
87 | * |
||||
88 | * @return bool True on success, false on failure |
||||
89 | */ |
||||
90 | public function connect() { |
||||
91 | $options = $this->_parseConfig(); |
||||
92 | |||||
93 | if (!empty($this->config['wsdl'])) { |
||||
94 | try { |
||||
95 | $this->client = new SoapClient($this->config['wsdl'], $options); |
||||
96 | return (bool)$this->client; |
||||
97 | } catch(SoapFault $fault) { |
||||
98 | $this->showError($fault->faultstring); |
||||
99 | } |
||||
100 | } |
||||
101 | |||||
102 | return false; |
||||
103 | } |
||||
104 | |||||
105 | /** |
||||
106 | * Sets the SoapClient instance to null. |
||||
107 | * |
||||
108 | * @return bool True |
||||
109 | */ |
||||
110 | public function close() { |
||||
111 | $this->client = null; |
||||
112 | $this->connected = false; |
||||
113 | |||||
114 | return true; |
||||
115 | } |
||||
116 | |||||
117 | /** |
||||
118 | * Returns the available SOAP methods. |
||||
119 | * |
||||
120 | * @param mixed $data Unused in this class. |
||||
121 | * @return array List of SOAP methods |
||||
122 | */ |
||||
123 | public function listSources($data = null) { |
||||
124 | return $this->client->__getFunctions(); |
||||
0 ignored issues
–
show
The method
__getFunctions() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * Query the SOAP server with the given method and parameters. |
||||
129 | * |
||||
130 | * @param string $method Name of method to call |
||||
131 | * @param array $queryData A list with parameters to pass |
||||
132 | * @return mixed Returns the result on success, false on failure |
||||
133 | */ |
||||
134 | public function query($method, $queryData = []) { |
||||
135 | if (!$this->connected) { |
||||
136 | return false; |
||||
137 | } |
||||
138 | |||||
139 | if (!empty($queryData)) { |
||||
140 | $queryData = [$queryData]; |
||||
141 | } |
||||
142 | |||||
143 | try { |
||||
144 | return $this->client->__soapCall($method, $queryData); |
||||
145 | } catch (SoapFault $fault) { |
||||
146 | $this->showError($fault->faultstring); |
||||
147 | return false; |
||||
148 | } |
||||
149 | } |
||||
150 | |||||
151 | /** |
||||
152 | * Returns the last SOAP response. |
||||
153 | * |
||||
154 | * @return string The last SOAP response |
||||
155 | */ |
||||
156 | public function getResponse() { |
||||
157 | return $this->client->__getLastResponse(); |
||||
158 | } |
||||
159 | |||||
160 | /** |
||||
161 | * Returns the last SOAP request. |
||||
162 | * |
||||
163 | * @return string The last SOAP request |
||||
164 | */ |
||||
165 | public function getRequest() { |
||||
166 | return $this->client->__getLastRequest(); |
||||
167 | } |
||||
168 | |||||
169 | /** |
||||
170 | * Writes an error message to log file. |
||||
171 | * |
||||
172 | * @param string $error Error message |
||||
173 | * @return void |
||||
174 | */ |
||||
175 | public function showError($error) { |
||||
176 | $message = __d('dpf_webservice', 'SOAP Error: %s', $error); |
||||
0 ignored issues
–
show
The function
__d was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
177 | CakeLog::error($message); |
||||
0 ignored issues
–
show
The type
CakeLog was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
178 | } |
||||
179 | |||||
180 | } |
||||
181 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths