freshcells /
soap-client-bundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Freshcells\SoapClientBundle\SoapClient; |
||
| 4 | |||
| 5 | use Freshcells\SoapClientBundle\Event\Event; |
||
| 6 | use Freshcells\SoapClientBundle\Event\Events; |
||
| 7 | use Freshcells\SoapClientBundle\Event\FaultEvent; |
||
| 8 | use Freshcells\SoapClientBundle\Event\RequestEvent; |
||
| 9 | use Freshcells\SoapClientBundle\Event\ResponseEvent; |
||
| 10 | use Ramsey\Uuid\Uuid; |
||
| 11 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
| 12 | use Symfony\Component\HttpKernel\Kernel; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class SoapClient |
||
| 16 | */ |
||
| 17 | class SoapClient extends \SoapClient implements SoapClientInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $options; |
||
| 23 | /** |
||
| 24 | * @var EventDispatcherInterface |
||
| 25 | */ |
||
| 26 | protected $dispatcher; |
||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | private $mockRequests = []; |
||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $mockResponses = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * SoapClient constructor. |
||
| 38 | * @param null $wsdl |
||
| 39 | * @param array|null $options |
||
| 40 | */ |
||
| 41 | 21 | public function __construct($wsdl = null, array $options = []) |
|
| 42 | { |
||
| 43 | |||
| 44 | 21 | if (isset($options['mock_requests'])) { |
|
| 45 | 15 | $this->setMockRequests($options['mock_requests']); |
|
| 46 | 15 | unset($options['mock_requests']); |
|
| 47 | } |
||
| 48 | 21 | if (isset($options['mock_responses'])) { |
|
| 49 | 12 | $this->setMockResponses($options['mock_responses']); |
|
| 50 | 12 | unset($options['mock_responses']); |
|
| 51 | } |
||
| 52 | |||
| 53 | $defaults = [ |
||
| 54 | 21 | 'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP), |
|
| 55 | 21 | 'cache_wsdl' => WSDL_CACHE_BOTH, |
|
| 56 | 21 | 'connection_timeout' => 60, |
|
| 57 | 'exceptions' => true, |
||
| 58 | 21 | 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, |
|
| 59 | 21 | 'soap_version' => SOAP_1_2, |
|
| 60 | 'trace' => true, |
||
| 61 | 21 | 'user_agent' => 'freshcells/soap-client-bundle', |
|
| 62 | ]; |
||
| 63 | |||
| 64 | 21 | $options = array_merge($defaults, $options); |
|
| 65 | |||
| 66 | 21 | $this->SoapClient($wsdl, $options); |
|
| 67 | 21 | $this->options = $options; |
|
| 68 | 21 | } |
|
| 69 | |||
| 70 | 6 | public function getOptions(): array |
|
| 71 | { |
||
| 72 | 6 | return $this->options; |
|
| 73 | } |
||
| 74 | |||
| 75 | 12 | public function __call($function_name, $arguments) |
|
| 76 | { |
||
| 77 | try { |
||
| 78 | 12 | $response = parent::__call($function_name, $arguments); |
|
| 79 | //works only with 'exceptions' => false, we always throw |
||
| 80 | 6 | if (is_soap_fault($response)) { |
|
| 81 | 6 | throw $response; |
|
| 82 | } |
||
| 83 | 6 | } catch (\Exception $e) { |
|
| 84 | 6 | $this->handleFault($function_name, $arguments, $e); |
|
| 85 | } |
||
| 86 | |||
| 87 | 6 | return $response; |
|
| 88 | } |
||
| 89 | |||
| 90 | public function __soapCall( |
||
| 91 | $function_name, |
||
| 92 | $arguments, |
||
| 93 | $options = null, |
||
| 94 | $input_headers = null, |
||
| 95 | &$output_headers = null |
||
| 96 | ) { |
||
| 97 | try { |
||
| 98 | $response = parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers); |
||
| 99 | //works only with 'exceptions' => false, we always throw |
||
| 100 | if (is_soap_fault($response)) { |
||
| 101 | throw $response; |
||
| 102 | } |
||
| 103 | } catch (\Exception $e) { |
||
| 104 | $this->handleFault($function_name, $arguments, $e); |
||
| 105 | } |
||
| 106 | |||
| 107 | return $response; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param string $request |
||
| 112 | * @param string $location |
||
| 113 | * @param string $action |
||
| 114 | * @param int $version |
||
| 115 | * @param null $one_way |
||
| 116 | * @return bool|string |
||
| 117 | */ |
||
| 118 | 6 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
|
| 119 | { |
||
| 120 | 6 | $id = Uuid::uuid1(); |
|
| 121 | |||
| 122 | 6 | foreach ($this->mockRequests as $key => $mockRequest) { |
|
| 123 | 6 | if (is_string($key)) { |
|
| 124 | 6 | if (strrpos($action, $key) !== false) { |
|
| 125 | 6 | $request = file_get_contents($mockRequest); |
|
| 126 | 6 | break; |
|
| 127 | } |
||
| 128 | } else { |
||
| 129 | if (is_callable($mockRequest)) { |
||
| 130 | if ($requestFilePath = $mockRequest($request, $location, $action, $version, $one_way)) { |
||
| 131 | $request = file_get_contents($requestFilePath); |
||
| 132 | break; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | 6 | $this->preCall($id->toString(), (string)$action, $request); |
|
| 139 | |||
| 140 | 6 | foreach ($this->mockResponses as $key => $mockResponse) { |
|
| 141 | 6 | if (is_string($key)) { |
|
| 142 | 3 | if (strrpos($action, $key) !== false) { |
|
| 143 | 3 | $response = file_get_contents($mockResponse); |
|
| 144 | |||
| 145 | 3 | $this->postCall($id->toString(), $action, $response); |
|
| 146 | |||
| 147 | 3 | return $response; |
|
| 148 | } |
||
| 149 | } else { |
||
| 150 | 3 | if (is_callable($mockResponse)) { |
|
| 151 | 3 | if ($responseFilePath = $mockResponse($request, $location, $action, $version, $one_way)) { |
|
| 152 | 3 | $response = file_get_contents($responseFilePath); |
|
| 153 | |||
| 154 | 3 | $this->postCall($id->toString(), $action, $response); |
|
| 155 | |||
| 156 | 3 | return $response; |
|
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | /* workaround for working timeout */ |
||
| 163 | $socketTimeout = false; |
||
| 164 | if (isset($this->options['connection_timeout'])) { |
||
| 165 | $socketTimeout = ini_set('default_socket_timeout', $this->options['connection_timeout']); |
||
| 166 | } |
||
| 167 | |||
| 168 | $response = parent::__doRequest($request, $location, $action, $version, $one_way); |
||
| 169 | |||
| 170 | $this->postCall($id->toString(), (string)$action, $response); |
||
| 171 | |||
| 172 | if ($socketTimeout !== false) { |
||
| 173 | ini_set('default_socket_timeout', $socketTimeout); |
||
| 174 | } |
||
| 175 | |||
| 176 | return $response; |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Triggered before a request is executed |
||
| 181 | * |
||
| 182 | * @param string $id |
||
| 183 | * @param string $resource |
||
| 184 | * @param string $requestContent |
||
| 185 | */ |
||
| 186 | 6 | protected function preCall(string $id, string $resource, string $requestContent = null) |
|
| 187 | { |
||
| 188 | 6 | $this->dispatch(new RequestEvent($id, $resource, $requestContent), Events::REQUEST); |
|
| 189 | 6 | } |
|
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $id |
||
| 193 | * @param string $resource |
||
| 194 | * @param string $response |
||
| 195 | */ |
||
| 196 | 6 | protected function postCall(string $id, string $resource, string $response = null) |
|
| 197 | { |
||
| 198 | 6 | $responseEvent = new ResponseEvent( |
|
| 199 | 6 | $id, |
|
| 200 | 6 | $resource, |
|
| 201 | 6 | $this->__getLastRequest(), |
|
| 202 | 6 | $this->__getLastRequestHeaders(), |
|
| 203 | 6 | $response, |
|
| 204 | 6 | $this->__getLastResponseHeaders() |
|
| 205 | ); |
||
| 206 | 6 | $this->dispatch($responseEvent, Events::RESPONSE); |
|
| 207 | 6 | } |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $id |
||
| 211 | * @param string $resource |
||
| 212 | * @param string $requestContent |
||
| 213 | * @param \Exception $exception |
||
| 214 | */ |
||
| 215 | 6 | protected function faultCall(string $id, string $resource, string $requestContent, \Exception $exception) |
|
| 216 | { |
||
| 217 | 6 | $this->dispatch( |
|
| 218 | 6 | new FaultEvent($id, $exception, new RequestEvent($id, $resource, $requestContent)), |
|
| 219 | 6 | Events::FAULT |
|
| 220 | ); |
||
| 221 | 6 | } |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @param array $mockRequests |
||
| 225 | */ |
||
| 226 | 15 | public function setMockRequests(array $mockRequests) |
|
| 227 | { |
||
| 228 | 15 | $this->mockRequests = $mockRequests; |
|
| 229 | 15 | } |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @param array $mockResponses |
||
| 233 | */ |
||
| 234 | 15 | public function setMockResponses(array $mockResponses) |
|
| 235 | { |
||
| 236 | 15 | $this->mockResponses = $mockResponses; |
|
| 237 | 15 | } |
|
| 238 | |||
| 239 | /** |
||
| 240 | * @param EventDispatcherInterface $dispatcher |
||
| 241 | * @required |
||
| 242 | */ |
||
| 243 | 21 | public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
| 244 | { |
||
| 245 | 21 | $this->dispatcher = $dispatcher; |
|
| 246 | 21 | } |
|
| 247 | |||
| 248 | /** |
||
| 249 | * @param $function_name |
||
| 250 | * @param $arguments |
||
| 251 | * @param $e |
||
| 252 | */ |
||
| 253 | 6 | protected function handleFault($function_name, $arguments, $e): void |
|
| 254 | { |
||
| 255 | 6 | $request = $this->__getLastRequest(); |
|
| 256 | 6 | if ($request === null) { //only dispatch this when no request was fired |
|
| 257 | 6 | $request = print_r($arguments, true); |
|
| 258 | 6 | $id = Uuid::uuid1(); |
|
| 259 | 6 | $this->faultCall($id->toString(), $function_name, $request, $e); |
|
| 260 | } |
||
| 261 | |||
| 262 | 6 | throw $e; |
|
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param Event $event |
||
| 267 | * @param string $eventName |
||
| 268 | */ |
||
| 269 | 12 | private function dispatch(Event $event, $eventName) |
|
| 270 | { |
||
| 271 | 12 | if (null === $this->dispatcher) { |
|
| 272 | return; |
||
| 273 | } |
||
| 274 | |||
| 275 | // EventDispatcher signature changed in Symfony 4.3 |
||
| 276 | 12 | if (Kernel::VERSION_ID < 40300) { |
|
| 277 | // Old EventDispatcher signature |
||
| 278 | 8 | $this->dispatcher->dispatch($eventName, $event); |
|
|
0 ignored issues
–
show
$event is of type object<Freshcells\SoapClientBundle\Event\Event>, but the function expects a null|string.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 279 | } else { |
||
| 280 | // New Symfony 4.3 EventDispatcher signature |
||
| 281 | 4 | $this->dispatcher->dispatch($event, $eventName); |
|
|
0 ignored issues
–
show
$event is of type object<Freshcells\SoapClientBundle\Event\Event>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 282 | } |
||
| 283 | 12 | } |
|
| 284 | } |
||
| 285 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: