/**
  * Create and init the soap client.
  *
  * @param MagentoSoapClientParameters $clientParameters
  * @param \SoapClient                 $soapClient
  * @param MagentoSoapClientProfiler   $profiler
  *
  * @throws ConnectionErrorException
  */
 public function __construct(MagentoSoapClientParameters $clientParameters, \SoapClient $soapClient = null, MagentoSoapClientProfiler $profiler = null)
 {
     $this->clientParameters = $clientParameters;
     $this->profiler = $profiler;
     if (!$soapClient) {
         $wsdlUrl = $this->clientParameters->getSoapUrl();
         $soapOptions = ['encoding' => 'UTF-8', 'trace' => true, 'exceptions' => true, 'login' => $this->clientParameters->getHttpLogin(), 'password' => $this->clientParameters->getHttpPassword(), 'cache_wsdl' => WSDL_CACHE_BOTH];
         try {
             $this->client = new \SoapClient($wsdlUrl, $soapOptions);
         } catch (\SoapFault $e) {
             throw new ConnectionErrorException('The soap connection could not be established', $e->getCode(), $e);
         }
     } else {
         $this->client = $soapClient;
     }
     $this->connect();
 }
 /**
  * It connects to the url and give response.
  *
  * @param MagentoSoapClientParameters $clientParameters
  *
  * @return \Guzzle\Http\Message\Response
  *
  * @throws \Exception
  */
 protected function connect($clientParameters)
 {
     $parametersHash = $clientParameters->getHash();
     if (!isset($this->resultCache[$parametersHash])) {
         $guzzleParams = ['connect_timeout' => self::CONNECT_TIMEOUT, 'timeout' => self::TIMEOUT, 'auth' => [$clientParameters->getHttpLogin(), $clientParameters->getHttpPassword()]];
         $request = $this->client->get($clientParameters->getSoapUrl(), [], $guzzleParams);
         $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
         $request->getCurlOptions()->set(CURLOPT_TIMEOUT, self::TIMEOUT);
         try {
             $response = $this->client->send($request);
             $this->resultCache[$parametersHash] = $response;
         } catch (\Exception $e) {
             $this->resultCache[$parametersHash] = $e;
             throw $e;
         }
     } else {
         $response = $this->resultCache[$parametersHash];
         if ($response instanceof \Exception) {
             throw $response;
         }
     }
     return $response;
 }