cs fixes
This commit is contained in:
parent
06ff1ab707
commit
3040718c9d
|
@ -55,11 +55,10 @@ class Curl
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @param int $followLocationMaxRedirects
|
* @param int $followLocationMaxRedirects
|
||||||
*/
|
*/
|
||||||
public function __construct( array $options, $followLocationMaxRedirects = 10 )
|
public function __construct(array $options, $followLocationMaxRedirects = 10)
|
||||||
{
|
{
|
||||||
// set the default HTTP user agent
|
// set the default HTTP user agent
|
||||||
if ( !isset( $options['user_agent'] ) )
|
if (!isset($options['user_agent'])) {
|
||||||
{
|
|
||||||
$options['user_agent'] = self::USER_AGENT;
|
$options['user_agent'] = self::USER_AGENT;
|
||||||
}
|
}
|
||||||
$this->followLocationMaxRedirects = $followLocationMaxRedirects;
|
$this->followLocationMaxRedirects = $followLocationMaxRedirects;
|
||||||
|
@ -76,33 +75,27 @@ class Curl
|
||||||
CURLOPT_USERAGENT => $options['user_agent'],
|
CURLOPT_USERAGENT => $options['user_agent'],
|
||||||
CURLINFO_HEADER_OUT => true,
|
CURLINFO_HEADER_OUT => true,
|
||||||
);
|
);
|
||||||
curl_setopt_array( $this->ch, $curlOptions );
|
curl_setopt_array($this->ch, $curlOptions);
|
||||||
if ( isset( $options['compression'] ) && !( $options['compression'] & SOAP_COMPRESSION_ACCEPT ) )
|
if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_ENCODING, 'identity');
|
||||||
curl_setopt( $this->ch, CURLOPT_ENCODING, 'identity' );
|
|
||||||
}
|
}
|
||||||
if ( isset( $options['connection_timeout'] ) )
|
if (isset($options['connection_timeout'])) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
|
||||||
curl_setopt( $this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout'] );
|
|
||||||
}
|
}
|
||||||
if ( isset( $options['proxy_host'] ) )
|
if (isset($options['proxy_host'])) {
|
||||||
{
|
$port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080;
|
||||||
$port = isset( $options['proxy_port'] ) ? $options['proxy_port'] : 8080;
|
curl_setopt($this->ch, CURLOPT_PROXY, $options['proxy_host'] . ':' . $port);
|
||||||
curl_setopt( $this->ch, CURLOPT_PROXY, $options['proxy_host'] . ':' . $port );
|
|
||||||
}
|
}
|
||||||
if ( isset( $options['proxy_user'] ) )
|
if (isset($options['proxy_user'])) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
|
||||||
curl_setopt( $this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password'] );
|
|
||||||
}
|
}
|
||||||
if ( isset( $options['login'] ) )
|
if (isset($options['login'])) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||||
curl_setopt( $this->ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
|
curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']);
|
||||||
curl_setopt( $this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password'] );
|
|
||||||
}
|
}
|
||||||
if ( isset( $options['local_cert'] ) )
|
if (isset($options['local_cert'])) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_SSLCERT, $options['local_cert']);
|
||||||
curl_setopt( $this->ch, CURLOPT_SSLCERT, $options['local_cert'] );
|
curl_setopt($this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase']);
|
||||||
curl_setopt( $this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase'] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +104,7 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
curl_close( $this->ch );
|
curl_close($this->ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,24 +116,22 @@ class Curl
|
||||||
* @param array $requestHeaders
|
* @param array $requestHeaders
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function exec( $location, $request = null, $requestHeaders = array() )
|
public function exec($location, $request = null, $requestHeaders = array())
|
||||||
{
|
{
|
||||||
curl_setopt( $this->ch, CURLOPT_URL, $location);
|
curl_setopt($this->ch, CURLOPT_URL, $location);
|
||||||
|
|
||||||
if ( !is_null( $request ) )
|
if (!is_null($request)) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_POST, true);
|
||||||
curl_setopt( $this->ch, CURLOPT_POST, true );
|
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request);
|
||||||
curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $request );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count( $requestHeaders ) > 0 )
|
if (count($requestHeaders) > 0) {
|
||||||
{
|
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $requestHeaders);
|
||||||
curl_setopt( $this->ch, CURLOPT_HTTPHEADER, $requestHeaders );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response = $this->execManualRedirect( $this->followLocationMaxRedirects );
|
$this->response = $this->execManualRedirect($this->followLocationMaxRedirects);
|
||||||
|
|
||||||
return ( $this->response === false ) ? false : true;
|
return ($this->response === false) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,43 +143,37 @@ class Curl
|
||||||
* @param int $redirects
|
* @param int $redirects
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function execManualRedirect( $redirects = 0 )
|
private function execManualRedirect($redirects = 0)
|
||||||
{
|
|
||||||
if ( $redirects > $this->followLocationMaxRedirects )
|
|
||||||
{
|
{
|
||||||
|
if ($redirects > $this->followLocationMaxRedirects) {
|
||||||
// TODO Redirection limit reached, aborting
|
// TODO Redirection limit reached, aborting
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
curl_setopt( $this->ch, CURLOPT_HEADER, true );
|
curl_setopt($this->ch, CURLOPT_HEADER, true);
|
||||||
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
$response = curl_exec( $this->ch );
|
$response = curl_exec($this->ch);
|
||||||
$httpResponseCode = curl_getinfo( $this->ch, CURLINFO_HTTP_CODE );
|
$httpResponseCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
|
||||||
if ( $httpResponseCode == 307 )
|
if ($httpResponseCode == 307) {
|
||||||
{
|
$headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
|
||||||
$headerSize = curl_getinfo( $this->ch, CURLINFO_HEADER_SIZE );
|
$header = substr($response, 0, $headerSize);
|
||||||
$header = substr( $response, 0, $headerSize );
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match( '/Location:(.*?)\n/', $header, $matches );
|
preg_match('/Location:(.*?)\n/', $header, $matches);
|
||||||
$url = trim( array_pop( $matches ) );
|
$url = trim(array_pop($matches));
|
||||||
// @parse_url to suppress E_WARNING for invalid urls
|
// @parse_url to suppress E_WARNING for invalid urls
|
||||||
if ( ( $url = @parse_url( $url ) ) !== false )
|
if (($url = @parse_url($url)) !== false) {
|
||||||
{
|
$lastUrl = parse_url(curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL));
|
||||||
$lastUrl = parse_url( curl_getinfo( $this->ch, CURLINFO_EFFECTIVE_URL ) );
|
if (!isset($url['scheme'])) {
|
||||||
if ( !isset( $url['scheme'] ) )
|
|
||||||
{
|
|
||||||
$url['scheme'] = $lastUrl['scheme'];
|
$url['scheme'] = $lastUrl['scheme'];
|
||||||
}
|
}
|
||||||
if ( !isset( $url['host'] ) )
|
if (!isset($url['host'])) {
|
||||||
{
|
|
||||||
$url['host'] = $lastUrl['host'];
|
$url['host'] = $lastUrl['host'];
|
||||||
}
|
}
|
||||||
if ( !isset( $url['path'] ) )
|
if (!isset($url['path'])) {
|
||||||
{
|
|
||||||
$url['path'] = $lastUrl['path'];
|
$url['path'] = $lastUrl['path'];
|
||||||
}
|
}
|
||||||
$newUrl = $url['scheme'] . '://' . $url['host'] . $url['path'] . ( $url['query'] ? '?' . $url['query'] : '' );
|
$newUrl = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query'] ? '?' . $url['query'] : '');
|
||||||
curl_setopt( $this->ch, CURLOPT_URL, $newUrl );
|
curl_setopt($this->ch, CURLOPT_URL, $newUrl);
|
||||||
return $this->execManualRedirect( $redirects++ );
|
return $this->execManualRedirect($redirects++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -240,12 +225,11 @@ class Curl
|
||||||
public function getErrorMessage()
|
public function getErrorMessage()
|
||||||
{
|
{
|
||||||
$errorCodeMapping = $this->getErrorCodeMapping();
|
$errorCodeMapping = $this->getErrorCodeMapping();
|
||||||
$errorNumber = curl_errno( $this->ch );
|
$errorNumber = curl_errno($this->ch);
|
||||||
if ( isset( $errorCodeMapping[$errorNumber] ) )
|
if (isset($errorCodeMapping[$errorNumber])) {
|
||||||
{
|
|
||||||
return $errorCodeMapping[$errorNumber];
|
return $errorCodeMapping[$errorNumber];
|
||||||
}
|
}
|
||||||
return curl_error( $this->ch );
|
return curl_error($this->ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +239,7 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getRequestHeaders()
|
public function getRequestHeaders()
|
||||||
{
|
{
|
||||||
return curl_getinfo( $this->ch, CURLINFO_HEADER_OUT );
|
return curl_getinfo($this->ch, CURLINFO_HEADER_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,8 +259,8 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getResponseBody()
|
public function getResponseBody()
|
||||||
{
|
{
|
||||||
$headerSize = curl_getinfo( $this->ch, CURLINFO_HEADER_SIZE );
|
$headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
|
||||||
return substr( $this->response, $headerSize );
|
return substr($this->response, $headerSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -286,7 +270,7 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getResponseContentType()
|
public function getResponseContentType()
|
||||||
{
|
{
|
||||||
return curl_getinfo( $this->ch, CURLINFO_CONTENT_TYPE );
|
return curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -296,8 +280,8 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getResponseHeaders()
|
public function getResponseHeaders()
|
||||||
{
|
{
|
||||||
$headerSize = curl_getinfo( $this->ch, CURLINFO_HEADER_SIZE );
|
$headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
|
||||||
return substr( $this->response, 0, $headerSize );
|
return substr($this->response, 0, $headerSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,7 +291,7 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getResponseStatusCode()
|
public function getResponseStatusCode()
|
||||||
{
|
{
|
||||||
return curl_getinfo( $this->ch, CURLINFO_HTTP_CODE );
|
return curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,7 +301,7 @@ class Curl
|
||||||
*/
|
*/
|
||||||
public function getResponseStatusMessage()
|
public function getResponseStatusMessage()
|
||||||
{
|
{
|
||||||
preg_match( '/HTTP\/(1\.[0-1]+) ([0-9]{3}) (.*)/', $this->response, $matches );
|
preg_match('/HTTP\/(1\.[0-1]+) ([0-9]{3}) (.*)/', $this->response, $matches);
|
||||||
return trim( array_pop( $matches ) );
|
return trim(array_pop($matches));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -171,12 +171,11 @@ class Helper
|
||||||
* @param string $errline
|
* @param string $errline
|
||||||
* @throws ErrorException
|
* @throws ErrorException
|
||||||
*/
|
*/
|
||||||
public static function exceptionErrorHandler( $errno, $errstr, $errfile, $errline )
|
public static function exceptionErrorHandler($errno, $errstr, $errfile, $errline)
|
||||||
{
|
{
|
||||||
// don't throw exception for errors suppresed with @
|
// don't throw exception for errors suppresed with @
|
||||||
if ( error_reporting() != 0 )
|
if (error_reporting() != 0) {
|
||||||
{
|
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||||
throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,18 +190,18 @@ class Helper
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||||
// 32 bits for "time_low"
|
// 32 bits for "time_low"
|
||||||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||||
// 16 bits for "time_mid"
|
// 16 bits for "time_mid"
|
||||||
mt_rand( 0, 0xffff ),
|
mt_rand(0, 0xffff),
|
||||||
// 16 bits for "time_hi_and_version",
|
// 16 bits for "time_hi_and_version",
|
||||||
// four most significant bits holds version number 4
|
// four most significant bits holds version number 4
|
||||||
mt_rand( 0, 0x0fff ) | 0x4000,
|
mt_rand(0, 0x0fff) | 0x4000,
|
||||||
// 16 bits, 8 bits for "clk_seq_hi_res",
|
// 16 bits, 8 bits for "clk_seq_hi_res",
|
||||||
// 8 bits for "clk_seq_low",
|
// 8 bits for "clk_seq_low",
|
||||||
// two most significant bits holds zero and one for variant DCE1.1
|
// two most significant bits holds zero and one for variant DCE1.1
|
||||||
mt_rand( 0, 0x3fff ) | 0x8000,
|
mt_rand(0, 0x3fff) | 0x8000,
|
||||||
// 48 bits for "node"
|
// 48 bits for "node"
|
||||||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,21 +213,17 @@ class Helper
|
||||||
public static function getCurrentUrl()
|
public static function getCurrentUrl()
|
||||||
{
|
{
|
||||||
$url = '';
|
$url = '';
|
||||||
if ( isset( $_SERVER['HTTPS'] ) &&
|
if (isset($_SERVER['HTTPS']) &&
|
||||||
( strtolower( $_SERVER['HTTPS'] ) === 'on' || $_SERVER['HTTPS'] === '1' ) )
|
(strtolower($_SERVER['HTTPS']) === 'on' || $_SERVER['HTTPS'] === '1')) {
|
||||||
{
|
|
||||||
$url .= 'https://';
|
$url .= 'https://';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$url .= 'http://';
|
$url .= 'http://';
|
||||||
}
|
}
|
||||||
$url .= isset( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : '';
|
$url .= isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
|
||||||
if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] != 80 )
|
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) {
|
||||||
{
|
|
||||||
$url .= ":{$_SERVER['SERVER_PORT']}";
|
$url .= ":{$_SERVER['SERVER_PORT']}";
|
||||||
}
|
}
|
||||||
$url .= isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
|
$url .= isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,14 +233,11 @@ class Helper
|
||||||
* @param int $version SOAP_1_1|SOAP_1_2
|
* @param int $version SOAP_1_1|SOAP_1_2
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getSoapNamespace( $version )
|
public static function getSoapNamespace($version)
|
||||||
{
|
|
||||||
if ( $version === SOAP_1_2 )
|
|
||||||
{
|
{
|
||||||
|
if ($version === SOAP_1_2) {
|
||||||
return self::NS_SOAP_1_2;
|
return self::NS_SOAP_1_2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return self::NS_SOAP_1_1;
|
return self::NS_SOAP_1_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,14 +248,11 @@ class Helper
|
||||||
* @param string $namespace NS_SOAP_1_1|NS_SOAP_1_2
|
* @param string $namespace NS_SOAP_1_1|NS_SOAP_1_2
|
||||||
* @return int SOAP_1_1|SOAP_1_2
|
* @return int SOAP_1_1|SOAP_1_2
|
||||||
*/
|
*/
|
||||||
public static function getSoapVersionFromNamespace( $namespace )
|
public static function getSoapVersionFromNamespace($namespace)
|
||||||
{
|
|
||||||
if ( $namespace === self::NS_SOAP_1_2 )
|
|
||||||
{
|
{
|
||||||
|
if ($namespace === self::NS_SOAP_1_2) {
|
||||||
return SOAP_1_2;
|
return SOAP_1_2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return SOAP_1_1;
|
return SOAP_1_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,46 +268,38 @@ class Helper
|
||||||
* @param \ass\Soap\WsdlHandler $wsdlHandler
|
* @param \ass\Soap\WsdlHandler $wsdlHandler
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function runPlugins( array $plugins, $requestType, $xml, $location = null, $action = null, \ass\Soap\WsdlHandler $wsdlHandler = null )
|
public static function runPlugins(array $plugins, $requestType, $xml, $location = null, $action = null, \ass\Soap\WsdlHandler $wsdlHandler = null)
|
||||||
{
|
|
||||||
if ( count( $plugins ) > 0 )
|
|
||||||
{
|
{
|
||||||
|
if (count($plugins) > 0) {
|
||||||
// instantiate new dom object
|
// instantiate new dom object
|
||||||
$dom = new \DOMDocument( '1.0' );
|
$dom = new \DOMDocument('1.0');
|
||||||
// format the XML if option is set
|
// format the XML if option is set
|
||||||
$dom->formatOutput = self::$formatXmlOutput;
|
$dom->formatOutput = self::$formatXmlOutput;
|
||||||
$dom->loadXML( $xml );
|
$dom->loadXML($xml);
|
||||||
$params = array(
|
$params = array(
|
||||||
$dom,
|
$dom,
|
||||||
$location,
|
$location,
|
||||||
$action,
|
$action,
|
||||||
$wsdlHandler
|
$wsdlHandler
|
||||||
);
|
);
|
||||||
if ( $requestType == self::REQUEST )
|
if ($requestType == self::REQUEST) {
|
||||||
{
|
|
||||||
$callMethod = 'modifyRequest';
|
$callMethod = 'modifyRequest';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$callMethod = 'modifyResponse';
|
$callMethod = 'modifyResponse';
|
||||||
}
|
}
|
||||||
// modify dom
|
// modify dom
|
||||||
foreach( $plugins AS $plugin )
|
foreach($plugins AS $plugin) {
|
||||||
{
|
if ($plugin instanceof \ass\Soap\Plugin) {
|
||||||
if ( $plugin instanceof \ass\Soap\Plugin )
|
call_user_func_array(array($plugin, $callMethod), $params);
|
||||||
{
|
|
||||||
call_user_func_array( array( $plugin, $callMethod ), $params );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return the modified xml document
|
// return the modified xml document
|
||||||
return $dom->saveXML();
|
return $dom->saveXML();
|
||||||
}
|
|
||||||
// format the XML if option is set
|
// format the XML if option is set
|
||||||
elseif ( self::$formatXmlOutput === true )
|
} elseif (self::$formatXmlOutput === true) {
|
||||||
{
|
$dom = new \DOMDocument('1.0');
|
||||||
$dom = new \DOMDocument( '1.0' );
|
|
||||||
$dom->formatOutput = true;
|
$dom->formatOutput = true;
|
||||||
$dom->loadXML( $xml );
|
$dom->loadXML($xml);
|
||||||
return $dom->saveXML();
|
return $dom->saveXML();
|
||||||
}
|
}
|
||||||
return $xml;
|
return $xml;
|
||||||
|
@ -329,16 +310,13 @@ class Helper
|
||||||
*
|
*
|
||||||
* @param boolean $reset
|
* @param boolean $reset
|
||||||
*/
|
*/
|
||||||
public static function setCustomErrorHandler( $reset = false )
|
public static function setCustomErrorHandler($reset = false)
|
||||||
{
|
{
|
||||||
if ( $reset === true && !is_null( self::$previousErrorHandler ) )
|
if ($reset === true && !is_null(self::$previousErrorHandler)) {
|
||||||
{
|
set_error_handler(self::$previousErrorHandler);
|
||||||
set_error_handler( self::$previousErrorHandler );
|
|
||||||
self::$previousErrorHandler = null;
|
self::$previousErrorHandler = null;
|
||||||
}
|
} else {
|
||||||
else
|
self::$previousErrorHandler = set_error_handler('ass\\Soap\\Helper::exceptionErrorHandler');
|
||||||
{
|
|
||||||
self::$previousErrorHandler = set_error_handler( 'ass\\Soap\\Helper::exceptionErrorHandler' );
|
|
||||||
}
|
}
|
||||||
return self::$previousErrorHandler;
|
return self::$previousErrorHandler;
|
||||||
}
|
}
|
||||||
|
@ -351,13 +329,13 @@ class Helper
|
||||||
* @param string $contentType
|
* @param string $contentType
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function makeSoapAttachmentDataString( $contentId, $contentType )
|
public static function makeSoapAttachmentDataString($contentId, $contentType)
|
||||||
{
|
{
|
||||||
$parameter = array(
|
$parameter = array(
|
||||||
'cid' => $contentId,
|
'cid' => $contentId,
|
||||||
'type' => $contentType,
|
'type' => $contentType,
|
||||||
);
|
);
|
||||||
return 'SOAP-MIME-ATTACHMENT:' . http_build_query( $parameter, null, '&' );
|
return 'SOAP-MIME-ATTACHMENT:' . http_build_query($parameter, null, '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,12 +345,12 @@ class Helper
|
||||||
* @param string $dataString
|
* @param string $dataString
|
||||||
* @return array(string=>string)
|
* @return array(string=>string)
|
||||||
*/
|
*/
|
||||||
public static function parseSoapAttachmentDataString( $dataString )
|
public static function parseSoapAttachmentDataString($dataString)
|
||||||
{
|
{
|
||||||
$dataString = substr( $dataString, 21 );
|
$dataString = substr($dataString, 21);
|
||||||
// get all data
|
// get all data
|
||||||
$data = array();
|
$data = array();
|
||||||
parse_str( $dataString, $data );
|
parse_str($dataString, $data);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,15 +360,12 @@ class Helper
|
||||||
*
|
*
|
||||||
* @param string $header
|
* @param string $header
|
||||||
*/
|
*/
|
||||||
public static function setHttpStatusHeader( $header )
|
public static function setHttpStatusHeader($header)
|
||||||
{
|
{
|
||||||
if ( substr( php_sapi_name(), 0, 3 ) == 'cgi' )
|
if ('cgi' == substr(php_sapi_name(), 0, 3)) {
|
||||||
{
|
header('Status: ' . $header);
|
||||||
header( 'Status: ' . $header );
|
} else {
|
||||||
}
|
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $header);
|
||||||
else
|
|
||||||
{
|
|
||||||
header( $_SERVER['SERVER_PROTOCOL'] . ' ' . $header );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -73,37 +73,30 @@ class SoapClient extends \SoapClient
|
||||||
* @param string $wsdl
|
* @param string $wsdl
|
||||||
* @param array(string=>mixed) $options
|
* @param array(string=>mixed) $options
|
||||||
*/
|
*/
|
||||||
public function __construct( $wsdl, array $options = array(), TypeConverterCollection $converters = null )
|
public function __construct($wsdl, array $options = array(), TypeConverterCollection $converters = null)
|
||||||
{
|
{
|
||||||
// we want the exceptions option to be set
|
// we want the exceptions option to be set
|
||||||
$options['exceptions'] = true;
|
$options['exceptions'] = true;
|
||||||
// set custom error handler that converts all php errors to ErrorExceptions
|
// set custom error handler that converts all php errors to ErrorExceptions
|
||||||
Helper::setCustomErrorHandler();
|
Helper::setCustomErrorHandler();
|
||||||
// we want to make sure we have the soap version to rely on it later
|
// we want to make sure we have the soap version to rely on it later
|
||||||
if ( !isset( $options['soap_version'] ) )
|
if (!isset($options['soap_version'])) {
|
||||||
{
|
|
||||||
$options['soap_version'] = SOAP_1_1;
|
$options['soap_version'] = SOAP_1_1;
|
||||||
}
|
}
|
||||||
// we want to make sure we have the features option
|
// we want to make sure we have the features option
|
||||||
if ( !isset( $options['features'] ) )
|
if (!isset($options['features'])) {
|
||||||
{
|
|
||||||
$options['features'] = 0;
|
$options['features'] = 0;
|
||||||
}
|
}
|
||||||
// set default option to resolve xsd includes
|
// set default option to resolve xsd includes
|
||||||
if ( !isset( $options['resolve_xsd_includes'] ) )
|
if (!isset($options['resolve_xsd_includes'])) {
|
||||||
{
|
|
||||||
$options['resolve_xsd_includes'] = true;
|
$options['resolve_xsd_includes'] = true;
|
||||||
}
|
}
|
||||||
// add type converters from TypeConverterCollection
|
// add type converters from TypeConverterCollection
|
||||||
if ( !is_null( $converters ) )
|
if (!is_null($converters)) {
|
||||||
{
|
|
||||||
$convertersTypemap = $converters->getTypemap();
|
$convertersTypemap = $converters->getTypemap();
|
||||||
if ( isset( $options['typemap'] ) )
|
if (isset($options['typemap'])) {
|
||||||
{
|
$options['typemap'] = array_merge($options['typemap'], $convertersTypemap);
|
||||||
$options['typemap'] = array_merge( $options['typemap'], $convertersTypemap );
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$options['typemap'] = $convertersTypemap;
|
$options['typemap'] = $convertersTypemap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,8 +108,8 @@ class SoapClient extends \SoapClient
|
||||||
$options['cache_wsdl'] = WSDL_CACHE_NONE;
|
$options['cache_wsdl'] = WSDL_CACHE_NONE;
|
||||||
// load WSDL and run parent constructor
|
// load WSDL and run parent constructor
|
||||||
// can't be loaded later as we need it already in the parent constructor
|
// can't be loaded later as we need it already in the parent constructor
|
||||||
$this->wsdlFile = $this->loadWsdl( $wsdl );
|
$this->wsdlFile = $this->loadWsdl($wsdl);
|
||||||
parent::__construct( $this->wsdlFile, $options );
|
parent::__construct($this->wsdlFile, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,18 +120,15 @@ class SoapClient extends \SoapClient
|
||||||
* @param string $action
|
* @param string $action
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function __doHttpRequest( $request, $location, $action )
|
private function __doHttpRequest($request, $location, $action)
|
||||||
{
|
{
|
||||||
// $request is if unmodified from SoapClient not a php string type!
|
// $request is if unmodified from SoapClient not a php string type!
|
||||||
$request = (string)$request;
|
$request = (string)$request;
|
||||||
if ( $this->options['soap_version'] == SOAP_1_2 )
|
if ($this->options['soap_version'] == SOAP_1_2) {
|
||||||
{
|
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type: application/soap+xml; charset=utf-8',
|
'Content-Type: application/soap+xml; charset=utf-8',
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type: text/xml; charset=utf-8',
|
'Content-Type: text/xml; charset=utf-8',
|
||||||
);
|
);
|
||||||
|
@ -146,27 +136,24 @@ class SoapClient extends \SoapClient
|
||||||
// add SOAPAction header
|
// add SOAPAction header
|
||||||
$headers[] = 'SOAPAction: "' . $action . '"';
|
$headers[] = 'SOAPAction: "' . $action . '"';
|
||||||
// new curl object for request
|
// new curl object for request
|
||||||
$curl = new Curl( $this->options );
|
$curl = new Curl($this->options);
|
||||||
// execute request
|
// execute request
|
||||||
$responseSuccessfull = $curl->exec( $location, $request, $headers );
|
$responseSuccessfull = $curl->exec($location, $request, $headers);
|
||||||
// tracing enabled: store last request header and body
|
// tracing enabled: store last request header and body
|
||||||
if ( isset( $this->options['trace'] ) && $this->options['trace'] === true )
|
if (isset($this->options['trace']) && $this->options['trace'] === true) {
|
||||||
{
|
|
||||||
$this->lastRequestHeaders = $curl->getRequestHeaders();
|
$this->lastRequestHeaders = $curl->getRequestHeaders();
|
||||||
$this->lastRequest = $request;
|
$this->lastRequest = $request;
|
||||||
}
|
}
|
||||||
// in case of an error while making the http request throw a soapFault
|
// in case of an error while making the http request throw a soapFault
|
||||||
if ( $responseSuccessfull === false )
|
if ($responseSuccessfull === false) {
|
||||||
{
|
|
||||||
// get error message from curl
|
// get error message from curl
|
||||||
$faultstring = $curl->getErrorMessage();
|
$faultstring = $curl->getErrorMessage();
|
||||||
// destruct curl object
|
// destruct curl object
|
||||||
unset( $curl );
|
unset($curl);
|
||||||
throw new \SoapFault( 'HTTP', $faultstring );
|
throw new \SoapFault('HTTP', $faultstring);
|
||||||
}
|
}
|
||||||
// tracing enabled: store last response header and body
|
// tracing enabled: store last response header and body
|
||||||
if ( isset( $this->options['trace'] ) && $this->options['trace'] === true )
|
if (isset($this->options['trace']) && $this->options['trace'] === true) {
|
||||||
{
|
|
||||||
$this->lastResponseHeaders = $curl->getResponseHeaders();
|
$this->lastResponseHeaders = $curl->getResponseHeaders();
|
||||||
$this->lastResponse = $curl->getResponseBody();
|
$this->lastResponse = $curl->getResponseBody();
|
||||||
}
|
}
|
||||||
|
@ -174,43 +161,32 @@ class SoapClient extends \SoapClient
|
||||||
// check if we do have a proper soap status code (if not soapfault)
|
// check if we do have a proper soap status code (if not soapfault)
|
||||||
// // TODO
|
// // TODO
|
||||||
// $responseStatusCode = $curl->getResponseStatusCode();
|
// $responseStatusCode = $curl->getResponseStatusCode();
|
||||||
// if ( $responseStatusCode >= 400 )
|
// if ($responseStatusCode >= 400) {
|
||||||
// {
|
|
||||||
// $isError = 0;
|
// $isError = 0;
|
||||||
// $response = trim( $response );
|
// $response = trim($response);
|
||||||
// if ( strlen( $response ) == 0 )
|
// if (strlen($response) == 0) {
|
||||||
// {
|
|
||||||
// $isError = 1;
|
// $isError = 1;
|
||||||
// }
|
// } else {
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// $contentType = $curl->getResponseContentType();
|
// $contentType = $curl->getResponseContentType();
|
||||||
// if ( $contentType != 'application/soap+xml'
|
// if ($contentType != 'application/soap+xml'
|
||||||
// && $contentType != 'application/soap+xml' )
|
// && $contentType != 'application/soap+xml') {
|
||||||
// {
|
// if (strncmp($response , "<?xml", 5)) {
|
||||||
// if ( strncmp( $response , "<?xml", 5 ) )
|
|
||||||
// {
|
|
||||||
// $isError = 1;
|
// $isError = 1;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if ( $isError == 1 )
|
// if ($isError == 1) {
|
||||||
// {
|
// throw new \SoapFault('HTTP', $curl->getResponseStatusMessage());
|
||||||
// throw new \SoapFault( 'HTTP', $curl->getResponseStatusMessage() );
|
|
||||||
// }
|
// }
|
||||||
// }
|
// } elseif ($responseStatusCode != 200 && $responseStatusCode != 202) {
|
||||||
// // TODO
|
// $dom = new \DOMDocument('1.0');
|
||||||
// elseif ( $responseStatusCode != 200 && $responseStatusCode != 202 )
|
// $dom->loadXML($response);
|
||||||
// {
|
// if ($dom->getElementsByTagNameNS($dom->documentElement->namespaceURI, 'Fault')->length == 0) {
|
||||||
// $dom = new \DOMDocument( '1.0' );
|
// throw new \SoapFault('HTTP', 'HTTP response status must be 200 or 202');
|
||||||
// $dom->loadXML( $response );
|
|
||||||
// if ( $dom->getElementsByTagNameNS( $dom->documentElement->namespaceURI, 'Fault' )->length == 0 )
|
|
||||||
// {
|
|
||||||
// throw new \SoapFault( 'HTTP', 'HTTP response status must be 200 or 202' );
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// destruct curl object
|
// destruct curl object
|
||||||
unset( $curl );
|
unset($curl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,10 +200,10 @@ class SoapClient extends \SoapClient
|
||||||
* @param int $one_way 0|1
|
* @param int $one_way 0|1
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __doRequest( $request, $location, $action, $version, $one_way = 0 )
|
public function __doRequest($request, $location, $action, $version, $one_way = 0)
|
||||||
{
|
{
|
||||||
// http request
|
// http request
|
||||||
$response = $this->__doHttpRequest( $request, $location, $action );
|
$response = $this->__doHttpRequest($request, $location, $action);
|
||||||
// return SOAP response to ext/soap
|
// return SOAP response to ext/soap
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -281,16 +257,13 @@ class SoapClient extends \SoapClient
|
||||||
* @param string $wsdl
|
* @param string $wsdl
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadWsdl( $wsdl )
|
private function loadWsdl($wsdl)
|
||||||
{
|
{
|
||||||
$wsdlDownloader = new WsdlDownloader( $this->options );
|
$wsdlDownloader = new WsdlDownloader($this->options);
|
||||||
try
|
try {
|
||||||
{
|
$cacheFileName = $wsdlDownloader->download($wsdl);
|
||||||
$cacheFileName = $wsdlDownloader->download( $wsdl );
|
} catch (\RuntimeException $e) {
|
||||||
}
|
throw new \SoapFault('WSDL', "SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl . "' : failed to load external entity \"" . $wsdl . "\"");
|
||||||
catch ( \RuntimeException $e )
|
|
||||||
{
|
|
||||||
throw new \SoapFault( 'WSDL', "SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl . "' : failed to load external entity \"" . $wsdl . "\"" );
|
|
||||||
}
|
}
|
||||||
return $cacheFileName;
|
return $cacheFileName;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue