Created
July 4, 2017 14:10
-
-
Save iamacarpet/8cf68fdfe5642016e026382f423b6ad2 to your computer and use it in GitHub Desktop.
SoapClientGuzzle extends \SoapClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use GuzzleHttp\Psr7; | |
use GuzzleHttp\Client; | |
use GuzzleHttp\Exception\ClientException; | |
use GuzzleHttp\Exception\RequestException; | |
class SoapClientGuzzle extends \SoapClient | |
{ | |
public $url = null; | |
public function __construct($wsdl, $options = array()) | |
{ | |
parent::__construct($wsdl, $options); | |
foreach ($options as $field => $value) { | |
if (!isset($this->$field)) { | |
$this->$field = $value; | |
} | |
} | |
} | |
public function __doRequest ($request, $location, $action, $version, $one_way = 0) | |
{ | |
$requestAction = 'post'; | |
$clientParams = [ | |
'verify'=>'/etc/ca-certificates.crt' | |
]; | |
$content = [ | |
'connect_timeout' => 2, | |
'timeout' => 30, | |
'body' => $request, | |
]; | |
if ($version === SOAP_1_2) { | |
$content['headers'][] = "Content-Type: application/soap+xml; charset=utf-8; action=\"{$action}\""; | |
} else { | |
$content['headers']['Content-Type'] = 'text/xml; charset=utf-8'; | |
$content['headers']['SOAPAction'] = "\"{$action}\""; | |
} | |
// create the HTTP client | |
$client = new Client($clientParams); | |
$response = $client->{$requestAction}( | |
$location, | |
$content | |
); | |
$response = (string)$response->getBody(); | |
//Return response info | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment