Skip to content

Instantly share code, notes, and snippets.

@iamacarpet
Created July 4, 2017 14:10
Show Gist options
  • Save iamacarpet/8cf68fdfe5642016e026382f423b6ad2 to your computer and use it in GitHub Desktop.
Save iamacarpet/8cf68fdfe5642016e026382f423b6ad2 to your computer and use it in GitHub Desktop.
SoapClientGuzzle extends \SoapClient
<?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