convert to unix line endings

This commit is contained in:
Andreas Schamberger 2011-10-16 19:49:24 +02:00
parent cfe1a966ab
commit 101169f7d6
3 changed files with 618 additions and 618 deletions

View File

@ -1,369 +1,369 @@
<?php <?php
/* /*
* This file is part of the BeSimpleSoapClient. * This file is part of the BeSimpleSoapClient.
* *
* (c) Christian Kerl <christian-kerl@web.de> * (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com> * (c) Francis Besset <francis.besset@gmail.com>
* *
* This source file is subject to the MIT license that is bundled * This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE. * with this source code in the file LICENSE.
*/ */
namespace BeSimple\SoapClient; namespace BeSimple\SoapClient;
/** /**
* Soap helper class with static functions that are used in the client and * Soap helper class with static functions that are used in the client and
* server implementations. It also provides namespace and configuration * server implementations. It also provides namespace and configuration
* constants. * constants.
* *
* @author Andreas Schamberger * @author Andreas Schamberger
*/ */
class Helper class Helper
{ {
/** /**
* Attachment type: xsd:base64Binary (native in ext/soap). * Attachment type: xsd:base64Binary (native in ext/soap).
*/ */
const ATTACHMENTS_TYPE_BASE64 = 1; const ATTACHMENTS_TYPE_BASE64 = 1;
/** /**
* Attachment type: MTOM (SOAP Message Transmission Optimization Mechanism). * Attachment type: MTOM (SOAP Message Transmission Optimization Mechanism).
*/ */
const ATTACHMENTS_TYPE_MTOM = 2; const ATTACHMENTS_TYPE_MTOM = 2;
/** /**
* Attachment type: SWA (SOAP Messages with Attachments). * Attachment type: SWA (SOAP Messages with Attachments).
*/ */
const ATTACHMENTS_TYPE_SWA = 4; const ATTACHMENTS_TYPE_SWA = 4;
/** /**
* Web Services Security: SOAP Message Security 1.0 (WS-Security 2004) * Web Services Security: SOAP Message Security 1.0 (WS-Security 2004)
*/ */
const NAME_WSS_SMS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0'; const NAME_WSS_SMS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0';
/** /**
* Web Services Security: SOAP Message Security 1.1 (WS-Security 2004) * Web Services Security: SOAP Message Security 1.1 (WS-Security 2004)
*/ */
const NAME_WSS_SMS_1_1 = 'http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1'; const NAME_WSS_SMS_1_1 = 'http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1';
/** /**
* Web Services Security UsernameToken Profile 1.0 * Web Services Security UsernameToken Profile 1.0
*/ */
const NAME_WSS_UTP = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0'; const NAME_WSS_UTP = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0';
/** /**
* Web Services Security X.509 Certificate Token Profile * Web Services Security X.509 Certificate Token Profile
*/ */
const NAME_WSS_X509 = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0'; const NAME_WSS_X509 = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0';
/** /**
* Soap 1.1 namespace. * Soap 1.1 namespace.
*/ */
const NS_SOAP_1_1 = 'http://schemas.xmlsoap.org/soap/envelope/'; const NS_SOAP_1_1 = 'http://schemas.xmlsoap.org/soap/envelope/';
/** /**
* Soap 1.1 namespace. * Soap 1.1 namespace.
*/ */
const NS_SOAP_1_2 = 'http://www.w3.org/2003/05/soap-envelope/'; const NS_SOAP_1_2 = 'http://www.w3.org/2003/05/soap-envelope/';
/** /**
* Web Services Addressing 1.0 namespace. * Web Services Addressing 1.0 namespace.
*/ */
const NS_WSA = 'http://www.w3.org/2005/08/addressing'; const NS_WSA = 'http://www.w3.org/2005/08/addressing';
/** /**
* Web Services Security Extension namespace. * Web Services Security Extension namespace.
*/ */
const NS_WSS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; const NS_WSS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
/** /**
* Web Services Security Utility namespace. * Web Services Security Utility namespace.
*/ */
const NS_WSU = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'; const NS_WSU = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
/** /**
* Describing Media Content of Binary Data in XML namespace. * Describing Media Content of Binary Data in XML namespace.
*/ */
const NS_XMLMIME = 'http://www.w3.org/2004/11/xmlmime'; const NS_XMLMIME = 'http://www.w3.org/2004/11/xmlmime';
/** /**
* XML Schema namespace. * XML Schema namespace.
*/ */
const NS_XML_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; const NS_XML_SCHEMA = 'http://www.w3.org/2001/XMLSchema';
/** /**
* XML Schema instance namespace. * XML Schema instance namespace.
*/ */
const NS_XML_SCHEMA_INSTANCE = 'http://www.w3.org/2001/XMLSchema-instance'; const NS_XML_SCHEMA_INSTANCE = 'http://www.w3.org/2001/XMLSchema-instance';
/** /**
* XML-binary Optimized Packaging namespace. * XML-binary Optimized Packaging namespace.
*/ */
const NS_XOP = 'http://www.w3.org/2004/08/xop/include'; const NS_XOP = 'http://www.w3.org/2004/08/xop/include';
/** /**
* Web Services Addressing 1.0 prefix. * Web Services Addressing 1.0 prefix.
*/ */
const PFX_WSA = 'wsa'; const PFX_WSA = 'wsa';
/** /**
* Web Services Security Extension namespace. * Web Services Security Extension namespace.
*/ */
const PFX_WSS = 'wsse'; const PFX_WSS = 'wsse';
/** /**
* Web Services Security Utility namespace prefix. * Web Services Security Utility namespace prefix.
*/ */
const PFX_WSU = 'wsu'; const PFX_WSU = 'wsu';
/** /**
* Describing Media Content of Binary Data in XML namespace prefix. * Describing Media Content of Binary Data in XML namespace prefix.
*/ */
const PFX_XMLMIME = 'xmlmime'; const PFX_XMLMIME = 'xmlmime';
/** /**
* XML Schema namespace prefix. * XML Schema namespace prefix.
*/ */
const PFX_XML_SCHEMA = 'xsd'; const PFX_XML_SCHEMA = 'xsd';
/** /**
* XML Schema instance namespace prefix. * XML Schema instance namespace prefix.
*/ */
const PFX_XML_SCHEMA_INSTANCE = 'xsi'; const PFX_XML_SCHEMA_INSTANCE = 'xsi';
/** /**
* XML-binary Optimized Packaging namespace prefix. * XML-binary Optimized Packaging namespace prefix.
*/ */
const PFX_XOP = 'xop'; const PFX_XOP = 'xop';
/** /**
* Constant for a request. * Constant for a request.
*/ */
const REQUEST = 0; const REQUEST = 0;
/** /**
* Constant for a response. * Constant for a response.
*/ */
const RESPONSE = 1; const RESPONSE = 1;
/** /**
* Wheather to format the XML output or not. * Wheather to format the XML output or not.
* *
* @var boolean * @var boolean
*/ */
public static $formatXmlOutput = false; public static $formatXmlOutput = false;
/** /**
* Contains previously defined error handler string. * Contains previously defined error handler string.
* *
* @var string * @var string
*/ */
private static $previousErrorHandler = null; private static $previousErrorHandler = null;
/** /**
* User-defined error handler function to convert errors to exceptions. * User-defined error handler function to convert errors to exceptions.
* *
* @param string $errno * @param string $errno
* @param string $errstr * @param string $errstr
* @param string $errfile * @param string $errfile
* @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);
} }
} }
/** /**
* Generate a pseudo-random version 4 UUID. * Generate a pseudo-random version 4 UUID.
* *
* @see http://de.php.net/manual/en/function.uniqid.php#94959 * @see http://de.php.net/manual/en/function.uniqid.php#94959
* @return string * @return string
*/ */
public static function generateUUID() public static function generateUUID()
{ {
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)
); );
} }
/** /**
* Builds the current URL from the $_SERVER array. * Builds the current URL from the $_SERVER array.
* *
* @return string * @return string
*/ */
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;
} }
/** /**
* Get SOAP namespace for the given $version. * Get SOAP namespace for the given $version.
* *
* @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;
} }
} }
/** /**
* Get SOAP version from namespace URI. * Get SOAP version from namespace URI.
* *
* @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;
} }
} }
/** /**
* Runs the registered Plugins on the given request $xml. * Runs the registered Plugins on the given request $xml.
* *
* @param array(\ass\Soap\Plugin) $plugins * @param array(\ass\Soap\Plugin) $plugins
* @param int $requestType \ass\Soap\Helper::REQUEST|\ass\Soap\Helper::RESPONSE * @param int $requestType \ass\Soap\Helper::REQUEST|\ass\Soap\Helper::RESPONSE
* @param string $xml * @param string $xml
* @param string $location * @param string $location
* @param string $action * @param string $action
* @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;
} }
/** /**
* Set custom error handler that converts all php errors to ErrorExceptions * Set custom error handler that converts all php errors to ErrorExceptions
* *
* @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;
} }
/** /**
* Build data string to used to bridge ext/soap * Build data string to used to bridge ext/soap
* 'SOAP_MIME_ATTACHMENT:cid=...&type=...' * 'SOAP_MIME_ATTACHMENT:cid=...&type=...'
* *
* @param string $contentId * @param string $contentId
* @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, '&');
} }
/** /**
* Parse data string used to bridge ext/soap * Parse data string used to bridge ext/soap
* 'SOAP_MIME_ATTACHMENT:cid=...&type=...' * 'SOAP_MIME_ATTACHMENT:cid=...&type=...'
* *
* @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;
} }
/** /**
* Function to set proper http status header. * Function to set proper http status header.
* Neccessary as there is a difference between mod_php and the cgi SAPIs. * Neccessary as there is a difference between mod_php and the cgi SAPIs.
* *
* @param string $header * @param string $header
*/ */
public static function setHttpStatusHeader($header) public static function setHttpStatusHeader($header)
{ {
if ('cgi' == substr(php_sapi_name(), 0, 3)) { if ('cgi' == substr(php_sapi_name(), 0, 3)) {
header('Status: ' . $header); header('Status: ' . $header);
} else { } else {
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $header); header($_SERVER['SERVER_PROTOCOL'] . ' ' . $header);
} }
} }
} }

View File

@ -22,31 +22,31 @@ namespace BeSimple\SoapClient;
*/ */
class SoapClient extends \SoapClient class SoapClient extends \SoapClient
{ {
/** /**
* Last request headers. * Last request headers.
* *
* @var string * @var string
*/ */
private $lastRequestHeaders = ''; private $lastRequestHeaders = '';
/** /**
* Last request. * Last request.
* *
* @var string * @var string
*/ */
private $lastRequest = ''; private $lastRequest = '';
/** /**
* Last response headers. * Last response headers.
* *
* @var string * @var string
*/ */
private $lastResponseHeaders = ''; private $lastResponseHeaders = '';
/** /**
* Last response. * Last response.
* *
* @var string * @var string
*/ */
private $lastResponse = ''; private $lastResponse = '';
@ -65,7 +65,7 @@ class SoapClient extends \SoapClient
private $wsdlFile = null; private $wsdlFile = null;
/** /**
* Extended constructor that saves the options as the parent class' * Extended constructor that saves the options as the parent class'
* property is private. * property is private.
* *
* @param string $wsdl * @param string $wsdl
@ -99,16 +99,16 @@ class SoapClient extends \SoapClient
} }
} }
// store local copy as ext/soap's property is private // store local copy as ext/soap's property is private
$this->options = $options; $this->options = $options;
// disable obsolete trace option for native SoapClient as we need to do our own tracing anyways // disable obsolete trace option for native SoapClient as we need to do our own tracing anyways
$options['trace'] = false; $options['trace'] = false;
// disable WSDL caching as we handle WSDL caching for remote URLs ourself // disable WSDL caching as we handle WSDL caching for remote URLs ourself
$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);
} }
/** /**
* Perform HTTP request with cURL. * Perform HTTP request with cURL.
@ -186,7 +186,7 @@ class SoapClient extends \SoapClient
// destruct curl object // destruct curl object
unset($curl); unset($curl);
return $response; return $response;
} }
/** /**
* Custom request method to be able to modify the SOAP messages. * Custom request method to be able to modify the SOAP messages.

View File

@ -1,227 +1,227 @@
<?php <?php
/* /*
* This file is part of the BeSimpleSoapClient. * This file is part of the BeSimpleSoapClient.
* *
* (c) Christian Kerl <christian-kerl@web.de> * (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com> * (c) Francis Besset <francis.besset@gmail.com>
* *
* This source file is subject to the MIT license that is bundled * This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE. * with this source code in the file LICENSE.
*/ */
namespace BeSimple\SoapClient; namespace BeSimple\SoapClient;
/** /**
* Downloads WSDL files with cURL. Uses all SoapClient options for * Downloads WSDL files with cURL. Uses all SoapClient options for
* authentication. Uses the WSDL_CACHE_* constants and the 'soap.wsdl_*' * authentication. Uses the WSDL_CACHE_* constants and the 'soap.wsdl_*'
* ini settings. Does only file caching as SoapClient only supports a file * ini settings. Does only file caching as SoapClient only supports a file
* name parameter. The class also resolves remote XML schema includes. * name parameter. The class also resolves remote XML schema includes.
* *
* @author Andreas Schamberger * @author Andreas Schamberger
*/ */
class WsdlDownloader class WsdlDownloader
{ {
/** /**
* Cache enabled. * Cache enabled.
* *
* @var bool * @var bool
*/ */
private $cacheEnabled; private $cacheEnabled;
/** /**
* Cache dir. * Cache dir.
* *
* @var string * @var string
*/ */
private $cacheDir; private $cacheDir;
/** /**
* Cache TTL. * Cache TTL.
* *
* @var int * @var int
*/ */
private $cacheTtl; private $cacheTtl;
/** /**
* Options array * Options array
* *
* @var array(string=>mixed) * @var array(string=>mixed)
*/ */
private $options = array(); private $options = array();
/** /**
* Constructor. * Constructor.
* *
* @param array $options * @param array $options
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
// get current WSDL caching config // get current WSDL caching config
$this->cacheEnabled = (bool)ini_get('soap.wsdl_cache_enabled'); $this->cacheEnabled = (bool)ini_get('soap.wsdl_cache_enabled');
if ($this->cacheEnabled === true if ($this->cacheEnabled === true
&& isset($options['cache_wsdl']) && isset($options['cache_wsdl'])
&& $options['cache_wsdl'] === WSDL_CACHE_NONE) { && $options['cache_wsdl'] === WSDL_CACHE_NONE) {
$this->cacheEnabled = false; $this->cacheEnabled = false;
} }
$this->cacheDir = ini_get('soap.wsdl_cache_dir'); $this->cacheDir = ini_get('soap.wsdl_cache_dir');
if (!is_dir($this->cacheDir)) { if (!is_dir($this->cacheDir)) {
$this->cacheDir = sys_get_temp_dir(); $this->cacheDir = sys_get_temp_dir();
} }
$this->cacheDir = rtrim($this->cacheDir, '/\\'); $this->cacheDir = rtrim($this->cacheDir, '/\\');
$this->cacheTtl = ini_get('soap.wsdl_cache_ttl'); $this->cacheTtl = ini_get('soap.wsdl_cache_ttl');
$this->options = $options; $this->options = $options;
if (!isset($this->options['resolve_xsd_includes'])) { if (!isset($this->options['resolve_xsd_includes'])) {
$this->options['resolve_xsd_includes'] = true; $this->options['resolve_xsd_includes'] = true;
} }
} }
/** /**
* Download given WSDL file and return name of cache file. * Download given WSDL file and return name of cache file.
* *
* @param string $wsdl * @param string $wsdl
* @return string * @return string
*/ */
public function download($wsdl) public function download($wsdl)
{ {
// download and cache remote WSDL files or local ones where we want to // download and cache remote WSDL files or local ones where we want to
// resolve remote XSD includes // resolve remote XSD includes
$isRemoteFile = $this->isRemoteFile($wsdl); $isRemoteFile = $this->isRemoteFile($wsdl);
if ($isRemoteFile === true || $this->options['resolve_xsd_includes'] === true) { if ($isRemoteFile === true || $this->options['resolve_xsd_includes'] === true) {
$cacheFile = $this->cacheDir . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdl) . '.cache'; $cacheFile = $this->cacheDir . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdl) . '.cache';
if ($this->cacheEnabled === false if ($this->cacheEnabled === false
|| !file_exists($cacheFile) || !file_exists($cacheFile)
|| (filemtime($cacheFile) + $this->cacheTtl) < time()) { || (filemtime($cacheFile) + $this->cacheTtl) < time()) {
if ($isRemoteFile === true) { if ($isRemoteFile === true) {
// 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($wsdl); $responseSuccessfull = $curl->exec($wsdl);
// get content // get content
if ($responseSuccessfull === true) { if ($responseSuccessfull === true) {
$response = $curl->getResponseBody(); $response = $curl->getResponseBody();
if ($this->options['resolve_xsd_includes'] === true) { if ($this->options['resolve_xsd_includes'] === true) {
$this->resolveXsdIncludes($response, $cacheFile, $wsdl); $this->resolveXsdIncludes($response, $cacheFile, $wsdl);
} else { } else {
file_put_contents($cacheFile, $response); file_put_contents($cacheFile, $response);
} }
} else { } else {
throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'"); throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'");
} }
} elseif (file_exists($wsdl)) { } elseif (file_exists($wsdl)) {
$response = file_get_contents($wsdl); $response = file_get_contents($wsdl);
$this->resolveXsdIncludes($response, $cacheFile); $this->resolveXsdIncludes($response, $cacheFile);
} else { } else {
throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'"); throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'");
} }
} }
return $cacheFile; return $cacheFile;
} elseif (file_exists($wsdl)) { } elseif (file_exists($wsdl)) {
return realpath($wsdl); return realpath($wsdl);
} else { } else {
throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'"); throw new \ErrorException("SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl ."'");
} }
} }
/** /**
* Do we have a remote file? * Do we have a remote file?
* *
* @param string $file * @param string $file
* @return boolean * @return boolean
*/ */
private function isRemoteFile($file) private function isRemoteFile($file)
{ {
$isRemoteFile = false; $isRemoteFile = false;
// @parse_url to suppress E_WARNING for invalid urls // @parse_url to suppress E_WARNING for invalid urls
if (($url = @parse_url($file)) !== false) { if (($url = @parse_url($file)) !== false) {
if (isset($url['scheme']) && substr($url['scheme'], 0, 4) == 'http') { if (isset($url['scheme']) && substr($url['scheme'], 0, 4) == 'http') {
$isRemoteFile = true; $isRemoteFile = true;
} }
} }
return $isRemoteFile; return $isRemoteFile;
} }
/** /**
* Resolves remote XSD includes within the WSDL files. * Resolves remote XSD includes within the WSDL files.
* *
* @param string $xml * @param string $xml
* @param string $cacheFile * @param string $cacheFile
* @param unknown_type $parentIsRemote * @param unknown_type $parentIsRemote
* @return string * @return string
*/ */
private function resolveXsdIncludes($xml, $cacheFile, $parentFile = null) private function resolveXsdIncludes($xml, $cacheFile, $parentFile = null)
{ {
$doc = new \DOMDocument(); $doc = new \DOMDocument();
$doc->loadXML($xml); $doc->loadXML($xml);
$xpath = new \DOMXPath($doc); $xpath = new \DOMXPath($doc);
$xpath->registerNamespace(Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA); $xpath->registerNamespace(Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA);
$query = './/' . Helper::PFX_XML_SCHEMA . ':include'; $query = './/' . Helper::PFX_XML_SCHEMA . ':include';
$nodes = $xpath->query($query); $nodes = $xpath->query($query);
if ($nodes->length > 0) { if ($nodes->length > 0) {
foreach ($nodes as $node) { foreach ($nodes as $node) {
$schemaLocation = $node->getAttribute('schemaLocation'); $schemaLocation = $node->getAttribute('schemaLocation');
if ($this->isRemoteFile($schemaLocation)) { if ($this->isRemoteFile($schemaLocation)) {
$schemaLocation = $this->download($schemaLocation); $schemaLocation = $this->download($schemaLocation);
$node->setAttribute('schemaLocation', $schemaLocation); $node->setAttribute('schemaLocation', $schemaLocation);
} elseif (!is_null($parentFile)) { } elseif (!is_null($parentFile)) {
$schemaLocation = $this->resolveRelativePathInUrl($parentFile, $schemaLocation); $schemaLocation = $this->resolveRelativePathInUrl($parentFile, $schemaLocation);
$schemaLocation = $this->download($schemaLocation); $schemaLocation = $this->download($schemaLocation);
$node->setAttribute('schemaLocation', $schemaLocation); $node->setAttribute('schemaLocation', $schemaLocation);
} }
} }
} }
$doc->save($cacheFile); $doc->save($cacheFile);
} }
/** /**
* Resolves the relative path to base into an absolute. * Resolves the relative path to base into an absolute.
* *
* @param string $base * @param string $base
* @param string $relative * @param string $relative
* @return string * @return string
*/ */
private function resolveRelativePathInUrl($base, $relative) private function resolveRelativePathInUrl($base, $relative)
{ {
$urlParts = parse_url($base); $urlParts = parse_url($base);
// combine base path with relative path // combine base path with relative path
if (isset($urlParts['path']) && strpos($relative, '/') === 0) { if (isset($urlParts['path']) && strpos($relative, '/') === 0) {
// $relative is absolute path from domain (starts with /) // $relative is absolute path from domain (starts with /)
$path = $relative; $path = $relative;
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) { } elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
// base path is directory // base path is directory
$path = $urlParts['path'] . $relative; $path = $urlParts['path'] . $relative;
} elseif (isset($urlParts['path'])) { } elseif (isset($urlParts['path'])) {
// strip filename from base path // strip filename from base path
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) . '/' . $relative; $path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) . '/' . $relative;
} else { } else {
// no base path // no base path
$path = '/' . $relative; $path = '/' . $relative;
} }
// foo/./bar ==> foo/bar // foo/./bar ==> foo/bar
$path = preg_replace('~/\./~', '/', $path); $path = preg_replace('~/\./~', '/', $path);
// remove double slashes // remove double slashes
$path = preg_replace('~/+~', '/', $path); $path = preg_replace('~/+~', '/', $path);
// split path by '/' // split path by '/'
$parts = explode('/', $path); $parts = explode('/', $path);
// resolve /../ // resolve /../
foreach ($parts as $key => $part) { foreach ($parts as $key => $part) {
if ($part == "..") { if ($part == "..") {
$keyToDelete = $key-1; $keyToDelete = $key-1;
while ($keyToDelete > 0) { while ($keyToDelete > 0) {
if (isset($parts[$keyToDelete])) { if (isset($parts[$keyToDelete])) {
unset($parts[$keyToDelete]); unset($parts[$keyToDelete]);
break; break;
} else { } else {
$keyToDelete--; $keyToDelete--;
} }
} }
unset($parts[$key]); unset($parts[$key]);
} }
} }
$hostname = $urlParts['scheme'] . '://' . $urlParts['host']; $hostname = $urlParts['scheme'] . '://' . $urlParts['host'];
if (isset($urlParts['port'])) { if (isset($urlParts['port'])) {
$hostname .= ':' . $urlParts['port']; $hostname .= ':' . $urlParts['port'];
} }
return $hostname . implode('/', $parts); return $hostname . implode('/', $parts);
} }
} }