Врзвращаем клиент после авторизации

@return SoapClient
@throws TurboSmsException
332175
private function _getClient()
    {

        $client = new SoapClient ($this->url);

        if (empty($this->credentials['login']) || empty($this->credentials['password'])) {
            throw new TurboSmsException('Enter login and password from Turbosms');
        }

        // Авторизируемся на сервере
        $result = $client->Auth($this->credentials);

        // @todo - может как-то адекватно статус отдавать и соотв. проверять его?
        if (0 && $result->AuthResultCode != 0) {
            throw new TurboSmsException($result->AuthResult);
        }

        // Пока будем проверять так
        // Надеюсь тех. специалисты прислушаются и доделают АПИ
        if ($result->AuthResult . '' != 'Вы успешно авторизировались') {
            throw new TurboSmsException($result->AuthResult);
        }

        return $client;

    }
1068981
private function soapCall(AbstractRequest $payload)
    {
        $request = $payload->getDocument();

        $envelope = $request->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'SOAP-ENV:Envelope');
        $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns1', self::NAMESPACE_N1);
        $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns2', self::NAMESPACE_N2);
        $envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns3', self::NAMESPACE_N3);

        $body = $request->createElement('SOAP-ENV:Body');
        $body->appendChild($payload->getElement());
        $envelope->appendChild($body);

        $request->appendChild($envelope);
        $xml = $request->saveXML();

        if ($this->debug) {
            var_dump($xml);
        }

        $response = $this->doRequest($xml);

        if ($this->debug) {
            var_dump($response);
        }

        if ($response === false) {
            throw new \Exception($this->getErrorMessage());
        }

        if (empty($response)) {
            throw new \Exception('Empty API response received');
        }

        $responseDoc = new \DOMDocument('1.0', 'UTF-8');
        $responseDoc->loadXML($response);

        $errorResponse = $this->checkForSoapFault($responseDoc);

        return $errorResponse !== null ? $errorResponse : $responseDoc;
    }
772438
private function createServer()
    {
        $server = new SoapServer(null, $this->soapServerOptions);
        $server->SetClass($this->wsdlclassname);
        $server->handle();
    }
717008
public function initSoapClient($_wsdlOptions)
    {
        $wsdlOptions = array();
        $defaultWsdlOptions = self::getDefaultWsdlOptions();
        foreach($defaultWsdlOptions as $optioName=>$optionValue)
        {
            if(array_key_exists($optioName,$_wsdlOptions) && !is_null($_wsdlOptions[$optioName])) {
                $wsdlOptions[str_replace('wsdl_', '', $optioName)] = $_wsdlOptions[$optioName];
            } elseif(!empty($optionValue)) {
                $wsdlOptions[str_replace('wsdl_', '', $optioName)] = $optionValue;
            }
        }

        if(array_key_exists(str_replace('wsdl_','',self::WSDL_URL),$wsdlOptions))
        {
            $wsdlUrl = $wsdlOptions[str_replace('wsdl_','',self::WSDL_URL)];
            unset($wsdlOptions[str_replace('wsdl_','',self::WSDL_URL)]);
            $soapClientClassName = self::getSoapClientClassName();

            $connection_timeout = 0;
            $retries = 1;
            $read_timeout = null;
            if(isset($_wsdlOptions['connection_options']) && is_array($_wsdlOptions['connection_options'])) {
                extract($_wsdlOptions['connection_options']);
                unset($_wsdlOptions['connection_options']);
            }

            @ini_set("soap.wsdl_cache_enabled", 0);
            if($soapClientClassName == '\Omniship\Rapido\Helper\SoapClient') {
                $soapClient = new $soapClientClassName($wsdlUrl,$wsdlOptions, $connection_timeout, $retries, $read_timeout);
            } else {
                $soapClient = new $soapClientClassName($wsdlUrl,$wsdlOptions);
            }

            self::setSoapClient($soapClient);
        }
    }
34567
public function initSoapClient()
    {
        if (is_object($this->soapClient) || $this->soapClient === false) {
            return;
        }
        try {
            $this->soapClient = new SoapClient(self::VAT_SERVICE_URL);
        } catch (SoapFault $e) {
            if (isset($this->config) && $this->config->get('vat_calculator.forward_soap_faults')) {
                throw new VATCheckUnavailableException($e->getMessage(), $e->getCode(), $e->getPrevious());
            }

            $this->soapClient = false;
        }
    }
233653
public function build()
    {
        $soapClientFactory = new SoapClientFactory();
        $soapClient = $soapClientFactory->create($this->wsdl);

        return new Client($soapClient);
    }
1330997
protected function getClient()
    {
        if ($this->client instanceof ClientInterface) {
            return $this->client;
        }

        if (empty($this->apiKey)) {
            throw new Exception('Use of connector not possible without API key', Exception::INVALID_API_KEY);
        }

        $this->client = new Client([
            'connect_timeout' => 10,
            'base_uri' => $this->serviceUrl,
            'headers' => array_merge($this->extraHeaders, [
                'User-Agent' => 'Connector-PHP/2',
                'X-Api-Key' => $this->apiKey,
            ])
        ]);

        return $this->client;
    }
1110473
public function buildCurlClient()
    {
        //
        // Use PHP Native cURL because the various Soap clients (BeSimple,
        // PHP native SoapClient) can't handle the WSDL file.
        //
        $this->curl = curl_init($this->getEndPoint());

        $sslCertificate = $this->getSslCertificate();
        $sslKey         = $this->getSslKey();
        $sslKeyPassword = $this->getSslKeyPassword();
        $userName       = $this->getUsername();
        $password       = $this->getPassword();
        $headers        = $this->getHeaders();

        // configuring cURL not to verify the server certificate
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);

        // setting the path where cURL can find the client certificate
        curl_setopt($this->curl, CURLOPT_SSLCERT, $sslCertificate);

        // setting the path where cURL can find the client certificate’s
        // private key
        curl_setopt($this->curl, CURLOPT_SSLKEY, $sslKey);

        // setting the key password
        curl_setopt($this->curl, CURLOPT_SSLKEYPASSWD, $sslKeyPassword);

        // setting the request type to POST
        curl_setopt($this->curl, CURLOPT_POST, 1);

        // setting the content type
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);

        // setting the authorization method to BASIC
        curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

        // supplying your credentials
        curl_setopt($this->curl, CURLOPT_USERPWD, $userName . ':' . $password);

        // telling cURL to return the HTTP response body as operation result
        // value when calling curl_exec
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

        return $this->curl;
    }
964619
protected function applySoapHeaders()
    {
        $headers = $this->request->getHeaders() ?: [];

        if ($headers instanceof SoapHeader) {

            $headers = [ $headers ];

        } else {

            foreach ($headers as &$header) {
                if ($header instanceof SoapHeader) continue;

                $namespace      = isset($header['namespace']) ? $header['namespace'] : null;
                $name           = isset($header['name']) ? $header['name'] : null;
                $data           = isset($header['data']) ? $header['data'] : null;
                $mustUnderstand = isset($header['mustunderstand']) ? $header['mustunderstand'] : null;
                $actor          = isset($header['actor']) ? $header['actor'] : null;

                $header = new SoapHeader($namespace, $name, $data, $mustUnderstand, $actor);
            }
        }

        unset($header);

        $this->client->__setSoapHeaders($headers);
    }
1189444
public function register()
  {
    $soapWrapper = new SoapWrapper();

    if (is_array($this->app['config']['soapwrapper'])) {
      $soapWrapper->addByArray($this->app['config']['soapwrapper']);
    }

    $this->app->bindIf(SoapWrapper::class, function () use ($soapWrapper) {
      return $soapWrapper;
    });
  }
1315884
private function initSoapClient() {
        if ($this->soapClient === NULL) {
            $this->soapClient = new SoapClient($this->service, $this->key, $this->cert, $this->trace, $this->passphrase);
        }
    }
272817
protected function sdkClient(): Client
    {
        $app = Container::getInstance();

        if ($app->bound('katsana')) {
            return $app->make('katsana');
        }

        return Client::make($this->clientId, $this->clientSecret);
    }
458579
protected function getSoap()
    {
        if ($this->SOAPClient === null) {
            $this->SOAPClient = new \SoapClient($this->url,
                [
                    'trace' => 1,
                    'cache_wsdl' => WSDL_CACHE_NONE
                ]);
            if ($this->location) {
                $this->SOAPClient->__setLocation($this->location);
            }
        }
        return $this->SOAPClient;
    }
394358
private function buildSoapClient() {
		$header = $this->buildAuthHeader();

		if($this->isTest())
			$location = self::DHL_SANDBOX_URL;
		else
			$location = self::DHL_PRODUCTION_URL;

		$auth_params = array(
			'login' => $this->getCredentials()->getApiUser(),
			'password' => $this->getCredentials()->getApiPassword(),
			'location' => $location,
			'trace' => 1
		);

		$this->setSoapClient(new SoapClient($this->getAPIUrl(), $auth_params));
		$this->getSoapClient()->__setSoapHeaders($header);
	}
273292
public function soapServerAction()
    {
        try {
            $apiModel = $this->_getModelName($this->obj);
            //parametry WSDL
            $wsdlParams = [
                'module' => 'cms',
                'controller' => 'api',
                'action' => 'wsdl',
                'obj' => $this->obj,
            ];
            //prywatny serwer
            if (\Mmi\App\FrontController::getInstance()->getEnvironment()->authUser) {
                $apiModel .= 'Private';
                $auth = new \Mmi\Security\Auth;
                $auth->setModelName($apiModel);
                $auth->httpAuth('Private API', 'Access denied!');
                $wsdlParams['type'] = 'private';
            }
            //ścieżka do WSDL
            $url = $this->view->url($wsdlParams, true, true, $this->_isSsl());
            //typ odpowiedzi na application/xml
            $this->getResponse()->setTypeXml();
            //powołanie klasy serwera SOAP
            $soap = new SoapServer($url);
            $soap->setClass($apiModel);
            //obsługa żądania
            $soap->handle();
            return '';
        } catch (\Exception $e) {
            //rzuca wyjątek internal
            return $this->_internalError($e);
        }
    }
406945
protected function performRequest($methodName, $params, array &$endpointOptions, array $soapOptions = [], array $soapHeaders = [])
    {
        $soapClient = $this->getSoapClient($endpointOptions);
        $response = null;

        if (!$soapClient) {
            throw new \RuntimeException('SoapConfigurableProducer requires a SoapClient as a dependency');
        }

        try {
            // creates a proper set of SoapHeader objects
            $processedSoapHeaders = array_map(function ($header) {
                if (is_array($header)) {
                    $header = new \SoapHeader($header[0], $header[1], $header[2]);
                }
                if (!$header instanceof \SoapHeader) {
                    throw new \InvalidArgumentException(sprintf(
                        'Invalid soap header "%s". Expected instance of \SoapHeader or array containing 3 values representing'.
                        ' "namespace", "header name" and "header value"',
                        json_encode($header)
                    ));
                }

                return $header;
            }, $soapHeaders);

            $soapClient->setExecutionTimeout($endpointOptions[ConfigurableWebserviceProtocol::OPTION_TIMEOUT]);

            $response = $soapClient->__soapCall($methodName, $params, $soapOptions, $processedSoapHeaders);

            $lastResponseCode = $soapClient->__getLastResponseCode();
            if ($lastResponseCode >= 400 && $lastResponseCode <= 599) {
                $this->throwUnrecoverableSoapProducerException('Unrecoverable error. SOAP HTTP Response code is '.$lastResponseCode.', 200 was expected.', $soapClient);
            } elseif (200 != $lastResponseCode) {
                $this->throwRecoverableSoapProducerException('Recoverable error. SOAP HTTP Response code is '.$lastResponseCode.', 200 was expected.', $soapClient);
            }
        } catch (\Exception $ex) {
            $this->throwRecoverableSoapProducerException($ex->getMessage(), $soapClient, $this->getDisplayResponseError(), $ex->getCode(), $ex);
        }

        return $response;
    }
343142
public function getOpenedClient()
    {
        if (!isset($this->openedClient)) {
            $this->openedClient = new ServiceClient();
            $this->openedClient->setApiKey($this->getParameter('apiKey'));

            $newClient = new \Zend\Http\Client(
                null,
                [
                    'adapter'       => 'Zend\Http\Client\Adapter\Socket',
                    'sslverifypeer' => false,
                ]
            );

            $this->openedClient->setHttpClient($newClient);
        }

        return $this->openedClient;
    }