3 Commits

5 changed files with 47 additions and 9 deletions

View File

@ -61,7 +61,7 @@ class SoapClient extends \SoapClient
$this->curl, $this->curl,
$soapOptions->getWsdlFile(), $soapOptions->getWsdlFile(),
$soapOptions->getWsdlCacheType(), $soapOptions->getWsdlCacheType(),
false $soapClientOptions->isResolveRemoteIncludes()
); );
} catch (Exception $e) { } catch (Exception $e) {
throw new SoapFault( throw new SoapFault(

View File

@ -81,4 +81,25 @@ class SoapClientOptionsBuilder
$endpointLocation $endpointLocation
); );
} }
/**
* @param SoapServerAuthenticationInterface $authentication
* @param bool $resolveRemoteIncludes
* @return SoapClientOptions
*/
public static function createWithAuthenticationAndResolveRemoteIncludes(
SoapServerAuthenticationInterface $authentication,
$resolveRemoteIncludes
) {
return new SoapClientOptions(
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
CurlOptions::DEFAULT_USER_AGENT,
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
$authentication,
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
SoapClientOptions::SOAP_CLIENT_ENDPOINT_LOCATION_NONE,
$resolveRemoteIncludes
);
}
} }

View File

@ -19,6 +19,9 @@ class SoapClientOptions
const SOAP_CLIENT_COMPRESSION_DEFLATE = CurlOptions::SOAP_COMPRESSION_DEFLATE; const SOAP_CLIENT_COMPRESSION_DEFLATE = CurlOptions::SOAP_COMPRESSION_DEFLATE;
const SOAP_CLIENT_AUTHENTICATION_NONE = null; const SOAP_CLIENT_AUTHENTICATION_NONE = null;
const SOAP_CLIENT_PROXY_NONE = null; const SOAP_CLIENT_PROXY_NONE = null;
const SOAP_CLIENT_ENDPOINT_LOCATION_NONE = null;
const SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_ON = true;
const SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_OFF = false;
private $trace; private $trace;
private $exceptions; private $exceptions;
@ -27,15 +30,17 @@ class SoapClientOptions
private $authentication; private $authentication;
private $proxy; private $proxy;
private $location; private $location;
private $resolveRemoteIncludes;
/** /**
* @param bool $trace = SoapClientOptions::SOAP_CLIENT_TRACE_ON|SoapClientOptions::SOAP_CLIENT_TRACE_OFF * @param bool $trace = self::SOAP_CLIENT_TRACE_ON|self::SOAP_CLIENT_TRACE_OFF
* @param bool $exceptions = SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON|SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_OFF * @param bool $exceptions = self::SOAP_CLIENT_EXCEPTIONS_ON|self::SOAP_CLIENT_EXCEPTIONS_OFF
* @param string $userAgent * @param string $userAgent
* @param int|null $compression = SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE|SoapClientOptions::SOAP_CLIENT_COMPRESSION_GZIP|SoapClientOptions::SOAP_CLIENT_COMPRESSION_DEFLATE * @param int|null $compression = self::SOAP_CLIENT_COMPRESSION_NONE|self::SOAP_CLIENT_COMPRESSION_GZIP|self::SOAP_CLIENT_COMPRESSION_DEFLATE
* @param SoapServerAuthenticationInterface|null $authentication * @param SoapServerAuthenticationInterface|null $authentication
* @param SoapServerProxy|null $proxy * @param SoapServerProxy|null $proxy
* @param string|null $location * @param string|null $location
* @param bool $resolveRemoteIncludes = self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_ON|self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_OFF
*/ */
public function __construct( public function __construct(
$trace, $trace,
@ -44,7 +49,8 @@ class SoapClientOptions
$compression = null, $compression = null,
SoapServerAuthenticationInterface $authentication = null, SoapServerAuthenticationInterface $authentication = null,
SoapServerProxy $proxy = null, SoapServerProxy $proxy = null,
$location = null $location = null,
$resolveRemoteIncludes = false
) { ) {
$this->trace = $trace; $this->trace = $trace;
$this->exceptions = $exceptions; $this->exceptions = $exceptions;
@ -53,6 +59,7 @@ class SoapClientOptions
$this->authentication = $authentication; $this->authentication = $authentication;
$this->proxy = $proxy; $this->proxy = $proxy;
$this->location = $location; $this->location = $location;
$this->resolveRemoteIncludes = $resolveRemoteIncludes;
} }
public function getTrace() public function getTrace()
@ -120,6 +127,11 @@ class SoapClientOptions
return $this->location; return $this->location;
} }
public function isResolveRemoteIncludes()
{
return $this->resolveRemoteIncludes;
}
public function toArray() public function toArray()
{ {
$optionsAsArray = [ $optionsAsArray = [

View File

@ -19,16 +19,16 @@ class RelativePathResolver
public function resolveRelativePathInUrl($base, $relative) public function resolveRelativePathInUrl($base, $relative)
{ {
$urlParts = parse_url($base); $urlParts = parse_url($base);
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..'); $pathIsSet = true === isset($urlParts['path']);
// combine base path with relative path // combine base path with relative path
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) { if (true === $pathIsSet && 0 < mb_strlen($relative) && 0 === strpos($relative, '/')) {
// $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 (true === $pathIsSet && 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 (true === $pathIsSet) {
// 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 {

View File

@ -30,6 +30,11 @@ class RelativePathResolverTest extends PHPUnit_Framework_TestCase
public function providePathInfo() public function providePathInfo()
{ {
return [ return [
[
'http://anyendpoint.tld:9999/path/to/endpoint.wsdl',
'../Schemas/Common/SoapHeader.xsd',
'http://anyendpoint.tld:9999/path/Schemas/Common/SoapHeader.xsd',
],
[ [
'http://endpoint-location.ltd/', 'http://endpoint-location.ltd/',
'Document1.xsd', 'Document1.xsd',