/** * @param string $wsdl * @param array $options * @param bool $force * * @return SoapClient * @throws \Exception */ protected function initSoapClient($wsdl = null, array $options = [], $force = false) { if (!self::$soapClientInstance || $force) { if ($wsdl === null) { $wsdl = "http://localhost/api/soap"; } $options = array_merge(['location' => $wsdl, 'soap_version' => SOAP_1_2], $options); $client = $this->getClientInstance(); if ($options['soap_version'] == SOAP_1_2) { $contentType = 'application/soap+xml'; } else { $contentType = 'text/xml'; } $client->request('GET', $wsdl, [], [], ['CONTENT_TYPE' => $contentType]); $status = $client->getResponse()->getStatusCode(); $wsdl = $client->getResponse()->getContent(); if ($status >= 400) { throw new \Exception($wsdl, $status); } //save to file $file = tempnam(sys_get_temp_dir(), date("Ymd") . '_') . '.xml'; $fl = fopen($file, "w"); fwrite($fl, $wsdl); fclose($fl); self::$soapClientInstance = new SoapClient($file, $options, $client); unlink($file); } $this->soapClient = self::$soapClientInstance; }
/** * @param string $wsdl * @param array $options * @param bool $force * * @return SoapClient * @throws \Exception */ protected function initSoapClient($wsdl = null, array $options = array(), $force = false) { if (!self::$soapClientInstance || $force) { if ($wsdl === null) { $wsdl = "http://localhost/api/soap"; } $options = array_merge(array('location' => $wsdl, 'soap_version' => SOAP_1_2), $options); $client = $this->getClientInstance(); $client->request('GET', $wsdl); $status = $client->getResponse()->getStatusCode(); $statusText = Response::$statusTexts[$status]; if ($status >= 400) { throw new \Exception($statusText, $status); } $wsdl = $client->getResponse()->getContent(); //save to file $file = tempnam(sys_get_temp_dir(), date("Ymd") . '_') . '.xml'; $fl = fopen($file, "w"); fwrite($fl, $wsdl); fclose($fl); self::$soapClientInstance = new SoapClient($file, $options, $client); unlink($file); } $this->soapClient = self::$soapClientInstance; }