/** * @param Client $client * @param HttpClientParameters $params * * @see SoapClient::SoapClient() */ public function __construct(Client $client, HttpClientParameters $params = null) { $this->client = $client; if (is_null($params)) { $params = new HttpClientParameters(); } $this->cache = $client->getCache(); $session = $client->getSession(); if (empty($params->baseUrl)) { $base_urls = $client->inDevMode() ? HttpClientParameters::$DEV_BASE_URLS : HttpClientParameters::$BASE_URLS; if (!isset($base_urls[$session->country->id])) { throw new \LogicException("I don't know baseUrl for country '{$session->country}', you have to supply one manually " . "into HttpClientParameters object found in ClientParameters"); } $params->baseUrl = $base_urls[$session->country->id]; } // this may throw $soapClient = new SoapClient(['encoding' => 'UTF-8', 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'cache_wsdl' => WSDL_CACHE_DISK, 'trace' => true, 'user_agent' => $params->userAgent, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'connection_timeout' => $params->connectionTimeout], $params->baseUrl, $this->client); $this->soapClient = $soapClient; }
/** * @return mixed Should return one of methodNameResponse objects from the Client\HttpClient\Wsdl namespace * @see \SoapClient::__soapCall() * @throws HttpClientException */ public function __soapCall($functionName, $arguments, $options = null, $inputHeaders = null, &$outputHeaders = null) { // Inject parameters if (count($arguments) > 0 && is_object($arguments[0])) { // request should be one of the *Request classes from the Wsdl namespace $request = $arguments[0]; foreach ($this->client->injectionParameters as $name => $val) { // following code is dependent on the naming convention of the WSDL2PHP generator $getterName = 'get' . ucfirst($name); $setterName = 'set' . ucfirst($name); if (property_exists($request, $name) && method_exists($request, $getterName) && is_null(call_user_func([$request, $getterName]) && method_exists($request, $setterName))) { call_user_func([$request, $setterName], $val); // set def val } } } // possible to add hooking here try { if ($this->isCacheable()) { $key = serialize(func_get_args()); $cache = $this->client->getCache(); $item = $cache->getItem($key); if ($item->isHit()) { $ret = $item->get(); } else { $ret = parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders); $item->set($ret, $this->cacheTtl); $cache->save($item); } } else { $ret = parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders); } } catch (\SoapFault $e) { throw new HttpClientException($e); } $this->resetCacheableStatus(); return $ret; }