Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
e6beef5a80 | |||
69a7005c35 | |||
073028f160 | |||
a9f11beb83 | |||
7ab8771989 | |||
d68c25daad | |||
6e117940a3 | |||
0c47f5a8d4 | |||
75a0489cce | |||
de5d6a2647 | |||
6970b7bbef |
@ -14,6 +14,8 @@ namespace BeSimple\SoapBundle\DependencyInjection;
|
|||||||
|
|
||||||
use BeSimple\SoapCommon\Cache;
|
use BeSimple\SoapCommon\Cache;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||||
|
use Carpages\Core\Entity\ContactPhone;
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
@ -41,6 +43,7 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
|
|
||||||
$loader->load('request.xml');
|
$loader->load('request.xml');
|
||||||
|
$loader->load('soap.xml');
|
||||||
|
|
||||||
$loader->load('loaders.xml');
|
$loader->load('loaders.xml');
|
||||||
$loader->load('converters.xml');
|
$loader->load('converters.xml');
|
||||||
@ -53,8 +56,8 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
|
|
||||||
$this->registerCacheConfiguration($config['cache'], $container, $loader);
|
$this->registerCacheConfiguration($config['cache'], $container, $loader);
|
||||||
|
|
||||||
if (!empty($config['clients'])) {
|
if ( ! empty($config['clients'])) {
|
||||||
$this->registerClientConfiguration($config['clients'], $container, $loader);
|
$this->registerClientConfiguration($config, $container, $loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
$container->setParameter('besimple.soap.definition.dumper.options.stylesheet', $config['wsdl_dumper']['stylesheet']);
|
$container->setParameter('besimple.soap.definition.dumper.options.stylesheet', $config['wsdl_dumper']['stylesheet']);
|
||||||
@ -69,11 +72,9 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
|
|
||||||
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||||
{
|
{
|
||||||
$loader->load('soap.xml');
|
|
||||||
|
|
||||||
$config['type'] = $this->getCacheType($config['type']);
|
$config['type'] = $this->getCacheType($config['type']);
|
||||||
|
|
||||||
foreach (array('type', 'lifetime', 'limit') as $key) {
|
foreach (array('type', 'file') as $key) {
|
||||||
$container->setParameter('besimple.soap.cache.'.$key, $config[$key]);
|
$container->setParameter('besimple.soap.cache.'.$key, $config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,22 +83,33 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
{
|
{
|
||||||
$loader->load('client.xml');
|
$loader->load('client.xml');
|
||||||
|
|
||||||
foreach ($config as $client => $options) {
|
foreach ($config['clients'] as $client => $options) {
|
||||||
$definition = new DefinitionDecorator('besimple.soap.client.builder');
|
$soapClientOpts = new DefinitionDecorator('besimple.soap.client_options');
|
||||||
$container->setDefinition(sprintf('besimple.soap.client.builder.%s', $client), $definition);
|
$soapOpts = new DefinitionDecorator('besimple.soap.options');
|
||||||
|
|
||||||
$definition->replaceArgument(0, $options['wsdl']);
|
$soapClientOptsService = sprintf('besimple.soap.client_options.%s', $client);
|
||||||
|
$soapOptsService = sprintf('besimple.soap.options.%s', $client);
|
||||||
|
|
||||||
$defOptions = $container
|
// configure SoapClient
|
||||||
->getDefinition('besimple.soap.client.builder')
|
$definition = new DefinitionDecorator('besimple.soap.client');
|
||||||
->getArgument(1);
|
|
||||||
|
|
||||||
foreach (array('cache_type', 'user_agent') as $key) {
|
$container->setDefinition(
|
||||||
if (isset($options[$key])) {
|
sprintf('besimple.soap.client.%s', $client),
|
||||||
$defOptions[$key] = $options[$key];
|
$definition
|
||||||
}
|
);
|
||||||
}
|
$container->setDefinition(
|
||||||
|
$soapClientOptsService,
|
||||||
|
$soapClientOpts
|
||||||
|
);
|
||||||
|
$container->setDefinition(
|
||||||
|
$soapOptsService,
|
||||||
|
$soapOpts
|
||||||
|
);
|
||||||
|
|
||||||
|
$definition->replaceArgument(0, new Reference($soapClientOptsService));
|
||||||
|
$definition->replaceArgument(1, new Reference($soapOptsService));
|
||||||
|
|
||||||
|
// configure proxy
|
||||||
$proxy = $options['proxy'];
|
$proxy = $options['proxy'];
|
||||||
if (false !== $proxy['host']) {
|
if (false !== $proxy['host']) {
|
||||||
if (null !== $proxy['auth']) {
|
if (null !== $proxy['auth']) {
|
||||||
@ -108,49 +120,58 @@ class BeSimpleSoapExtension extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->addMethodCall('withProxy', array(
|
$proxy = $this->createClientProxy($client, $proxy, $container);
|
||||||
$proxy['host'], $proxy['port'],
|
$soapClientOpts->setFactory([
|
||||||
$proxy['login'], $proxy['password'],
|
'%besimple.soap.client_options_builder.class%',
|
||||||
$proxy['auth']
|
'createWithProxy'
|
||||||
));
|
]);
|
||||||
|
$soapClientOpts->setArgument(0, new Reference($proxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($defOptions['cache_type'])) {
|
// configure SoapOptions for client
|
||||||
$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
|
$classMap = $this->createClientClassMap($client, $options['classmap'], $container);
|
||||||
|
|
||||||
|
$soapOpts->replaceArgument(0, $config['cache']['file']);
|
||||||
|
$soapOpts->replaceArgument(1, new Reference($classMap));
|
||||||
|
$soapOpts->replaceArgument(2, $this->getCacheType($config['cache']['type']));
|
||||||
|
|
||||||
|
if ($config['cache']['version'] == SoapOptions::SOAP_VERSION_1_1) {
|
||||||
|
$soapOpts->setFactory([
|
||||||
|
'%besimple.soap.options_builder.class%',
|
||||||
|
'createWithClassMapV11'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->replaceArgument(1, $defOptions);
|
|
||||||
|
|
||||||
$classmap = $this->createClientClassmap($client, $options['classmap'], $container);
|
|
||||||
$definition->replaceArgument(2, new Reference($classmap));
|
|
||||||
|
|
||||||
$this->createClient($client, $container);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createClientClassmap($client, array $classmap, ContainerBuilder $container)
|
private function createClientClassMap($client, array $classmap, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new DefinitionDecorator('besimple.soap.classmap');
|
$definition = new DefinitionDecorator('besimple.soap.classmap');
|
||||||
$container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition);
|
$container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition);
|
||||||
|
|
||||||
if (!empty($classmap)) {
|
if ( ! empty($classmap)) {
|
||||||
$definition->setMethodCalls(array(
|
$definition->setMethodCalls(array(
|
||||||
array('set', array($classmap)),
|
array('__construct', array($classmap)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf('besimple.soap.classmap.%s', $client);
|
return sprintf('besimple.soap.classmap.%s', $client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createClient($client, ContainerBuilder $container)
|
private function createClientProxy($client, array $proxy, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new DefinitionDecorator('besimple.soap.client');
|
$definition = new DefinitionDecorator('besimple.soap.client.proxy');
|
||||||
$container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
|
$container->setDefinition(sprintf('besimple.soap.client.proxy.%s', $client), $definition);
|
||||||
|
|
||||||
$definition->setFactory(array(
|
if ( ! empty($proxy)) {
|
||||||
new Reference(sprintf('besimple.soap.client.builder.%s', $client)),
|
$definition->replaceArgument(0, $proxy['host']);
|
||||||
'build'
|
$definition->replaceArgument(1, $proxy['port']);
|
||||||
));
|
$definition->replaceArgument(2, $proxy['login']);
|
||||||
|
$definition->replaceArgument(3, $proxy['password']);
|
||||||
|
$definition->replaceArgument(4, $proxy['auth']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf('besimple.soap.client.proxy.%s', $client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
||||||
|
@ -64,6 +64,10 @@ class Configuration
|
|||||||
->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes)))
|
->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes)))
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
->scalarNode('version')->defaultNull()->end()
|
||||||
|
->scalarNode('encoding')->defaultNull()->end()
|
||||||
|
->scalarNode('keepalive')->defaultNull()->end()
|
||||||
|
->scalarNode('file')->defaultNull()->end()
|
||||||
->scalarNode('lifetime')->defaultNull()->end()
|
->scalarNode('lifetime')->defaultNull()->end()
|
||||||
->scalarNode('limit')->defaultNull()->end()
|
->scalarNode('limit')->defaultNull()->end()
|
||||||
->end()
|
->end()
|
||||||
|
@ -4,26 +4,26 @@
|
|||||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
<parameters>
|
<parameters>
|
||||||
<parameter key="besimple.soap.client.builder.class">BeSimple\SoapBundle\Soap\SoapClientBuilder</parameter>
|
<parameter key="besimple.soap.client.builder.class">BeSimple\SoapClient\SoapClientBuilder</parameter>
|
||||||
<parameter key="besimple.soap.classmap.class">BeSimple\SoapCommon\Classmap</parameter>
|
<parameter key="besimple.soap.client.class">BeSimple\SoapClient\SoapClient</parameter>
|
||||||
|
<parameter key="besimple.soap.client.proxy.class">BeSimple\SoapClient\SoapServerProxy\SoapServerProxy</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="besimple.soap.client.builder" class="%besimple.soap.client.builder.class%" abstract="true">
|
|
||||||
<argument /> <!-- wsdl URI -->
|
<service id="besimple.soap.client" class="%besimple.soap.client.class%" abstract="true">
|
||||||
<argument type="collection">
|
<factory class="%besimple.soap.client.builder.class%" method="build" />
|
||||||
<argument key="debug">%kernel.debug%</argument>
|
<argument type="service" id="besimple.soap.client_options" />
|
||||||
</argument>
|
<argument type="service" id="besimple.soap.options" /> <!-- hack to load besimple cache configuration -->
|
||||||
<argument type="service" id="besimple.soap.classmap" />
|
|
||||||
<argument type="service" id="besimple.soap.converter.collection" />
|
|
||||||
<argument type="service" id="besimple.soap.cache" /> <!-- hack to load besimple cache configuration -->
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.client" class="%besimple.soap.client.builder.class%" abstract="true">
|
<service id="besimple.soap.client.proxy" class="%besimple.soap.client.proxy.class%" abstract="true">
|
||||||
<factory class="besimple.soap.client.builder" method="build" />
|
<argument id="$host" />
|
||||||
|
<argument id="$port" />
|
||||||
|
<argument id="$login" />
|
||||||
|
<argument id="$password" />
|
||||||
|
<argument id="$authenticationType" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</container>
|
</container>
|
||||||
|
@ -1,20 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<container xmlns="http://symfony.com/schema/dic/services"
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
<parameters>
|
<parameters>
|
||||||
<parameter key="besimple.soap.cache.class">BeSimple\SoapBundle\Cache</parameter>
|
<parameter key="besimple.soap.classmap.class">BeSimple\SoapCommon\ClassMap</parameter>
|
||||||
<parameter key="besimple.soap.cache.dir">%kernel.cache_dir%/besimple/soap</parameter>
|
<parameter key="besimple.soap.client_options.class">BeSimple\SoapClient\SoapOptions\SoapClientOptions</parameter>
|
||||||
|
<parameter key="besimple.soap.client_options_builder.class">BeSimple\SoapClient\SoapClientOptionsBuilder</parameter>
|
||||||
|
<parameter key="besimple.soap.options.class">BeSimple\SoapCommon\SoapOptions\SoapOptions</parameter>
|
||||||
|
<parameter key="besimple.soap.options_builder.class">BeSimple\SoapCommon\SoapOptionsBuilder</parameter>
|
||||||
|
<parameter key="besimple.soap.cache.dir">%kernel.cache_dir%</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="besimple.soap.cache" class="%besimple.soap.cache.class%">
|
<service id="besimple.soap.client_options" class="%besimple.soap.client_options.class%" abstract="true">
|
||||||
<argument>%kernel.debug%</argument>
|
<!-- call the static method -->
|
||||||
|
<factory class="%besimple.soap.client_options_builder.class%" method="createWithDefaults" />
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
||||||
|
|
||||||
|
<service id="besimple.soap.options" class="%besimple.soap.options.class%" abstract="true">
|
||||||
|
<factory class="%besimple.soap.options_builder.class%" method="createWithClassMap" />
|
||||||
|
<argument>%besimple.soap.cache.file%</argument>
|
||||||
|
<argument type="service" id="besimple.soap.classmap" />
|
||||||
<argument>%besimple.soap.cache.type%</argument>
|
<argument>%besimple.soap.cache.type%</argument>
|
||||||
<argument>%besimple.soap.cache.dir%/cache</argument>
|
<argument>%besimple.soap.cache.dir%</argument>
|
||||||
<argument>%besimple.soap.cache.lifetime%</argument>
|
|
||||||
<argument>%besimple.soap.cache.limit%</argument>
|
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<parameter key="besimple.soap.binder.request_header.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestHeaderMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.request_header.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestHeaderMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
||||||
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapCommon\Definition\Type\TypeRepository</parameter>
|
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapCommon\Definition\Type\TypeRepository</parameter>
|
||||||
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapServer\Classmap</parameter>
|
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapCommon\ClassMap</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
|
@ -4,7 +4,6 @@ namespace BeSimple\SoapClient\Curl;
|
|||||||
|
|
||||||
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
|
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
|
||||||
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
|
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
|
||||||
use BeSimple\SoapClient\Curl\Http\SslCertificateOptions;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class Curl
|
class Curl
|
||||||
@ -141,6 +140,11 @@ class Curl
|
|||||||
curl_setopt($curlSession, CURLOPT_CAPATH, $sslCertificateOptions->hasCertificateAuthorityPath());
|
curl_setopt($curlSession, CURLOPT_CAPATH, $sslCertificateOptions->hasCertificateAuthorityPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($options->hasSslVersion()) {
|
||||||
|
curl_setopt($curlSession, CURLOPT_SSLVERSION, $options->getSslVersion());
|
||||||
|
}
|
||||||
|
|
||||||
$executeSoapCallResponse = $this->executeHttpCall($curlSession, $options);
|
$executeSoapCallResponse = $this->executeHttpCall($curlSession, $options);
|
||||||
|
|
||||||
$httpRequestHeadersAsString = curl_getinfo($curlSession, CURLINFO_HEADER_OUT);
|
$httpRequestHeadersAsString = curl_getinfo($curlSession, CURLINFO_HEADER_OUT);
|
||||||
@ -159,7 +163,7 @@ class Curl
|
|||||||
$httpResponseCode
|
$httpResponseCode
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!is_integer($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) {
|
if (!is_int($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) {
|
||||||
|
|
||||||
return new CurlResponse(
|
return new CurlResponse(
|
||||||
$this->normalizeStringOrFalse($httpRequestHeadersAsString),
|
$this->normalizeStringOrFalse($httpRequestHeadersAsString),
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapClient\Curl;
|
namespace BeSimple\SoapClient\Curl;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
|
||||||
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
|
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions;
|
||||||
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationInterface;
|
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationInterface;
|
||||||
use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions;
|
|
||||||
use BeSimple\SoapClient\Curl\Http\SslCertificateOptions;
|
use BeSimple\SoapClient\Curl\Http\SslCertificateOptions;
|
||||||
use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy;
|
use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy;
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ class CurlOptions
|
|||||||
private $proxy;
|
private $proxy;
|
||||||
private $httpAuthentication;
|
private $httpAuthentication;
|
||||||
private $sslCertificateOptions;
|
private $sslCertificateOptions;
|
||||||
|
private $sslVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $userAgent
|
* @param string $userAgent
|
||||||
@ -31,6 +32,7 @@ class CurlOptions
|
|||||||
* @param SoapServerProxy|null $proxy
|
* @param SoapServerProxy|null $proxy
|
||||||
* @param HttpAuthenticationInterface|null $httpAuthentication
|
* @param HttpAuthenticationInterface|null $httpAuthentication
|
||||||
* @param SslCertificateOptions|null $sslCertificateOptions
|
* @param SslCertificateOptions|null $sslCertificateOptions
|
||||||
|
* @param int $sslVersion
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$userAgent,
|
$userAgent,
|
||||||
@ -39,7 +41,8 @@ class CurlOptions
|
|||||||
$connectionTimeout,
|
$connectionTimeout,
|
||||||
SoapServerProxy $proxy = null,
|
SoapServerProxy $proxy = null,
|
||||||
HttpAuthenticationInterface $httpAuthentication = null,
|
HttpAuthenticationInterface $httpAuthentication = null,
|
||||||
SslCertificateOptions $sslCertificateOptions = null
|
SslCertificateOptions $sslCertificateOptions = null,
|
||||||
|
$sslVersion = null
|
||||||
) {
|
) {
|
||||||
$this->userAgent = $userAgent;
|
$this->userAgent = $userAgent;
|
||||||
$this->followLocationMaxRedirects = $followLocationMaxRedirects;
|
$this->followLocationMaxRedirects = $followLocationMaxRedirects;
|
||||||
@ -48,6 +51,7 @@ class CurlOptions
|
|||||||
$this->proxy = $proxy;
|
$this->proxy = $proxy;
|
||||||
$this->httpAuthentication = $httpAuthentication;
|
$this->httpAuthentication = $httpAuthentication;
|
||||||
$this->sslCertificateOptions = $sslCertificateOptions;
|
$this->sslCertificateOptions = $sslCertificateOptions;
|
||||||
|
$this->sslVersion = $sslVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserAgent()
|
public function getUserAgent()
|
||||||
@ -123,4 +127,14 @@ class CurlOptions
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasSslVersion()
|
||||||
|
{
|
||||||
|
return $this->sslVersion !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSslVersion()
|
||||||
|
{
|
||||||
|
return $this->sslVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ class CurlOptionsBuilder
|
|||||||
self::DEFAULT_CONNECTION_TIMEOUT,
|
self::DEFAULT_CONNECTION_TIMEOUT,
|
||||||
$soapClientOptions->getProxy(),
|
$soapClientOptions->getProxy(),
|
||||||
self::getHttpAuthOptions($soapClientOptions),
|
self::getHttpAuthOptions($soapClientOptions),
|
||||||
self::getSslCertificateOptions($soapClientOptions)
|
self::getSslCertificateOptions($soapClientOptions),
|
||||||
|
$soapClientOptions->getSslVersion()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(
|
||||||
|
@ -45,6 +45,18 @@ class SoapClientOptionsBuilder
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function createWithProxy($proxy)
|
||||||
|
{
|
||||||
|
return new SoapClientOptions(
|
||||||
|
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||||
|
CurlOptions::DEFAULT_USER_AGENT,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_AUTHENTICATION_NONE,
|
||||||
|
$proxy
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function createWithEndpointLocation($endpointLocation)
|
public static function createWithEndpointLocation($endpointLocation)
|
||||||
{
|
{
|
||||||
return new SoapClientOptions(
|
return new SoapClientOptions(
|
||||||
@ -81,4 +93,47 @@ class SoapClientOptionsBuilder
|
|||||||
$endpointLocation
|
$endpointLocation
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $endpointLocation
|
||||||
|
* @param SoapServerAuthenticationInterface $authentication
|
||||||
|
* @return SoapClientOptions
|
||||||
|
*/
|
||||||
|
public static function createWithAuthenticationAndEndpointLocationAndSslVersionV3(
|
||||||
|
$endpointLocation,
|
||||||
|
SoapServerAuthenticationInterface $authentication
|
||||||
|
) {
|
||||||
|
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,
|
||||||
|
$endpointLocation,
|
||||||
|
false,
|
||||||
|
CURL_SSLVERSION_SSLv3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,19 @@ class SoapClientOptions
|
|||||||
private $authentication;
|
private $authentication;
|
||||||
private $proxy;
|
private $proxy;
|
||||||
private $location;
|
private $location;
|
||||||
|
private $resolveRemoteIncludes;
|
||||||
|
private $sslVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
|
* @param int $sslVersion
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$trace,
|
$trace,
|
||||||
@ -44,7 +51,9 @@ class SoapClientOptions
|
|||||||
$compression = null,
|
$compression = null,
|
||||||
SoapServerAuthenticationInterface $authentication = null,
|
SoapServerAuthenticationInterface $authentication = null,
|
||||||
SoapServerProxy $proxy = null,
|
SoapServerProxy $proxy = null,
|
||||||
$location = null
|
$location = null,
|
||||||
|
$resolveRemoteIncludes = false,
|
||||||
|
$sslVersion = null
|
||||||
) {
|
) {
|
||||||
$this->trace = $trace;
|
$this->trace = $trace;
|
||||||
$this->exceptions = $exceptions;
|
$this->exceptions = $exceptions;
|
||||||
@ -53,6 +62,8 @@ class SoapClientOptions
|
|||||||
$this->authentication = $authentication;
|
$this->authentication = $authentication;
|
||||||
$this->proxy = $proxy;
|
$this->proxy = $proxy;
|
||||||
$this->location = $location;
|
$this->location = $location;
|
||||||
|
$this->resolveRemoteIncludes = $resolveRemoteIncludes;
|
||||||
|
$this->sslVersion = $sslVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTrace()
|
public function getTrace()
|
||||||
@ -120,6 +131,11 @@ class SoapClientOptions
|
|||||||
return $this->location;
|
return $this->location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isResolveRemoteIncludes()
|
||||||
|
{
|
||||||
|
return $this->resolveRemoteIncludes;
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
$optionsAsArray = [
|
$optionsAsArray = [
|
||||||
@ -142,4 +158,9 @@ class SoapClientOptions
|
|||||||
|
|
||||||
return $optionsAsArray;
|
return $optionsAsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSslVersion()
|
||||||
|
{
|
||||||
|
return $this->sslVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
namespace BeSimple\SoapClient;
|
namespace BeSimple\SoapClient;
|
||||||
|
|
||||||
use BeSimple\SoapClient\Curl\Curl;
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\Xml\RemoteFileResolver;
|
||||||
|
use BeSimple\SoapClient\Xml\XmlFileDomDocumentProcessor;
|
||||||
use BeSimple\SoapCommon\Cache;
|
use BeSimple\SoapCommon\Cache;
|
||||||
use BeSimple\SoapCommon\Helper;
|
use BeSimple\SoapCommon\Helper;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
@ -30,6 +32,11 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class WsdlDownloader
|
class WsdlDownloader
|
||||||
{
|
{
|
||||||
|
public static function instantiateDownloader()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Curl $curl
|
* @param Curl $curl
|
||||||
* @param string $wsdlPath WSDL file URL/path
|
* @param string $wsdlPath WSDL file URL/path
|
||||||
@ -39,10 +46,10 @@ class WsdlDownloader
|
|||||||
*/
|
*/
|
||||||
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
|
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
|
||||||
{
|
{
|
||||||
$isRemoteFile = $this->isRemoteFile($wsdlPath);
|
$isRemoteFile = RemoteFileResolver::instantiateResolver()->isRemoteFile($wsdlPath);
|
||||||
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
|
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
|
||||||
if ($isCacheEnabled === true) {
|
if ($isCacheEnabled === true) {
|
||||||
$cacheFilePath = Cache::getDirectory().DIRECTORY_SEPARATOR.'wsdl_'.md5($wsdlPath).'.cache';
|
$cacheFilePath = Cache::getDirectory() . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdlPath) . '.cache';
|
||||||
$isCacheExisting = file_exists($cacheFilePath);
|
$isCacheExisting = file_exists($cacheFilePath);
|
||||||
if ($isCacheExisting) {
|
if ($isCacheExisting) {
|
||||||
$fileModificationTime = filemtime($cacheFilePath);
|
$fileModificationTime = filemtime($cacheFilePath);
|
||||||
@ -54,46 +61,17 @@ class WsdlDownloader
|
|||||||
$isCacheExisting = $isCacheValid = false;
|
$isCacheExisting = $isCacheValid = false;
|
||||||
}
|
}
|
||||||
if ($isCacheExisting === false || $isCacheValid === false) {
|
if ($isCacheExisting === false || $isCacheValid === false) {
|
||||||
$this->writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
|
XmlFileDomDocumentProcessor::writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getLocalWsdlPath($cacheFilePath);
|
return $this->getLocalWsdlPath($cacheFilePath);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($isRemoteFile === true) {
|
|
||||||
return $wsdlPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getLocalWsdlPath($wsdlPath);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function writeCacheFile(Curl $curl, $cacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile)
|
|
||||||
{
|
|
||||||
if ($isRemoteFile === true) {
|
if ($isRemoteFile === true) {
|
||||||
$curlResponse = $curl->executeCurlWithCachedSession($wsdlPath);
|
return $wsdlPath;
|
||||||
if ($curlResponse->curlStatusSuccess()) {
|
|
||||||
if (mb_strlen($curlResponse->getResponseBody()) === 0) {
|
|
||||||
throw new Exception('Could not write WSDL cache file: empty curl response from: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
if ($resolveRemoteIncludes === true) {
|
|
||||||
$document = $this->getXmlFileDomDocument($curl, $cacheType, $curlResponse->getResponseBody(), $wsdlPath);
|
|
||||||
$this->saveXmlDomDocument($document, $cacheFilePath);
|
|
||||||
} else {
|
|
||||||
file_put_contents($cacheFilePath, $curlResponse->getResponseBody());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Exception('Could not write WSDL cache file: Download failed with message: '.$curlResponse->getCurlErrorMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (file_exists($wsdlPath)) {
|
|
||||||
$document = $this->getXmlFileDomDocument($curl, $cacheType, file_get_contents($wsdlPath));
|
|
||||||
$this->saveXmlDomDocument($document, $cacheFilePath);
|
|
||||||
} else {
|
|
||||||
throw new Exception('Could write WSDL cache file: local file does not exist: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->getLocalWsdlPath($wsdlPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLocalWsdlPath($wsdlPath)
|
private function getLocalWsdlPath($wsdlPath)
|
||||||
@ -104,164 +82,6 @@ class WsdlDownloader
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('Could not download WSDL: local file does not exist: '.$wsdlPath);
|
throw new Exception('Could not download WSDL: local file does not exist: ' . $wsdlPath);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $wsdlPath File URL/path
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function isRemoteFile($wsdlPath)
|
|
||||||
{
|
|
||||||
$parsedUrlOrFalse = @parse_url($wsdlPath);
|
|
||||||
if ($parsedUrlOrFalse !== false) {
|
|
||||||
if (isset($parsedUrlOrFalse['scheme']) && substr($parsedUrlOrFalse['scheme'], 0, 4) === 'http') {
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception('Could not determine wsdlPath is remote: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves remote WSDL/XSD includes within the WSDL files.
|
|
||||||
*
|
|
||||||
* @param Curl $curl
|
|
||||||
* @param int $cacheType
|
|
||||||
* @param string $xmlFileSource XML file contents
|
|
||||||
* @param boolean $parentFilePath Parent file name
|
|
||||||
* @return DOMDocument
|
|
||||||
*/
|
|
||||||
private function getXmlFileDomDocument(Curl $curl, $cacheType, $xmlFileSource, $parentFilePath = null)
|
|
||||||
{
|
|
||||||
$document = new DOMDocument('1.0', 'utf-8');
|
|
||||||
if ($document->loadXML($xmlFileSource) === false) {
|
|
||||||
throw new Exception('Could not save downloaded WSDL cache: '.$xmlFileSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
$xpath = new DOMXPath($document);
|
|
||||||
$this->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_WSDL, Helper::NS_WSDL, 'location', $parentFilePath);
|
|
||||||
$this->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA, 'schemaLocation', $parentFilePath);
|
|
||||||
|
|
||||||
return $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveXmlDomDocument(DOMDocument $document, $cacheFilePath)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$xmlContents = $document->saveXML();
|
|
||||||
if ($xmlContents === '') {
|
|
||||||
throw new Exception('Could not write WSDL cache file: DOMDocument returned empty XML file');
|
|
||||||
}
|
|
||||||
file_put_contents($cacheFilePath, $xmlContents);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
unlink($cacheFilePath);
|
|
||||||
throw new Exception('Could not write WSDL cache file: save method returned error: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateXmlDocument(
|
|
||||||
Curl $curl,
|
|
||||||
$cacheType,
|
|
||||||
DOMXPath $xpath,
|
|
||||||
$schemaPrefix,
|
|
||||||
$schemaUrl,
|
|
||||||
$locationAttributeName,
|
|
||||||
$parentFilePath = null
|
|
||||||
) {
|
|
||||||
$xpath->registerNamespace($schemaPrefix, $schemaUrl);
|
|
||||||
$nodes = $xpath->query('.//'.$schemaPrefix.':include | .//'.$schemaPrefix.':import');
|
|
||||||
if ($nodes->length > 0) {
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
/** @var DOMElement $node */
|
|
||||||
$locationPath = $node->getAttribute($locationAttributeName);
|
|
||||||
if ($locationPath !== '') {
|
|
||||||
if ($this->isRemoteFile($locationPath)) {
|
|
||||||
$node->setAttribute(
|
|
||||||
$locationAttributeName,
|
|
||||||
$this->getWsdlPath(
|
|
||||||
$curl,
|
|
||||||
$locationPath,
|
|
||||||
$cacheType,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} elseif ($parentFilePath !== null) {
|
|
||||||
$node->setAttribute(
|
|
||||||
$locationAttributeName,
|
|
||||||
$this->getWsdlPath(
|
|
||||||
$curl,
|
|
||||||
$this->resolveRelativePathInUrl($parentFilePath, $locationPath),
|
|
||||||
$cacheType,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves the relative path to base into an absolute.
|
|
||||||
*
|
|
||||||
* @param string $base Base path
|
|
||||||
* @param string $relative Relative path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function resolveRelativePathInUrl($base, $relative)
|
|
||||||
{
|
|
||||||
$urlParts = parse_url($base);
|
|
||||||
|
|
||||||
// combine base path with relative path
|
|
||||||
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && '/' === $relative{0}) {
|
|
||||||
// $relative is absolute path from domain (starts with /)
|
|
||||||
$path = $relative;
|
|
||||||
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
|
|
||||||
// base path is directory
|
|
||||||
$path = $urlParts['path'].$relative;
|
|
||||||
} elseif (isset($urlParts['path'])) {
|
|
||||||
// strip filename from base path
|
|
||||||
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
|
||||||
} else {
|
|
||||||
// no base path
|
|
||||||
$path = '/'.$relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
// foo/./bar ==> foo/bar
|
|
||||||
// remove double slashes
|
|
||||||
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
|
|
||||||
|
|
||||||
// split path by '/'
|
|
||||||
$parts = explode('/', $path);
|
|
||||||
|
|
||||||
// resolve /../
|
|
||||||
foreach ($parts as $key => $part) {
|
|
||||||
if ($part === '..') {
|
|
||||||
$keyToDelete = $key - 1;
|
|
||||||
while ($keyToDelete > 0) {
|
|
||||||
if (isset($parts[$keyToDelete])) {
|
|
||||||
unset($parts[$keyToDelete]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$keyToDelete--;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($parts[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
|
|
||||||
if (isset($urlParts['port'])) {
|
|
||||||
$hostname .= ':'.$urlParts['port'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $hostname.implode('/', $parts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
75
src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php
Normal file
75
src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml\Path;
|
||||||
|
|
||||||
|
class RelativePathResolver
|
||||||
|
{
|
||||||
|
public static function instantiateResolver()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the relative path to base into an absolute.
|
||||||
|
*
|
||||||
|
* @param string $base Base path
|
||||||
|
* @param string $relative Relative path
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function resolveRelativePathInUrl($base, $relative)
|
||||||
|
{
|
||||||
|
$urlParts = parse_url($base);
|
||||||
|
$pathIsSet = true === isset($urlParts['path']);
|
||||||
|
|
||||||
|
// combine base path with relative path
|
||||||
|
if (true === $pathIsSet && 0 < mb_strlen($relative) && 0 === strpos($relative, '/')) {
|
||||||
|
// $relative is absolute path from domain (starts with /)
|
||||||
|
$path = $relative;
|
||||||
|
} elseif (true === $pathIsSet && strrpos($urlParts['path'], '/') === strlen($urlParts['path'])) {
|
||||||
|
// base path is directory
|
||||||
|
$path = $urlParts['path'].$relative;
|
||||||
|
} elseif (true === $pathIsSet) {
|
||||||
|
// strip filename from base path
|
||||||
|
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
||||||
|
} else {
|
||||||
|
// no base path
|
||||||
|
$path = '/'.$relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
// foo/./bar ==> foo/bar
|
||||||
|
// remove double slashes
|
||||||
|
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
|
||||||
|
|
||||||
|
// split path by '/'
|
||||||
|
$parts = explode('/', $path);
|
||||||
|
|
||||||
|
// resolve /../
|
||||||
|
foreach ($parts as $key => $part) {
|
||||||
|
if ($part === '..') {
|
||||||
|
$keyToDelete = $key - 1;
|
||||||
|
while ($keyToDelete > 0) {
|
||||||
|
if (isset($parts[$keyToDelete])) {
|
||||||
|
unset($parts[$keyToDelete]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keyToDelete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($parts[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
|
||||||
|
if (isset($urlParts['port'])) {
|
||||||
|
$hostname .= ':'.$urlParts['port'];
|
||||||
|
}
|
||||||
|
$implodedParts = implode('/', $parts);
|
||||||
|
if (substr($implodedParts, 0, 1) !== '/') {
|
||||||
|
$implodedParts = '/'.$implodedParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hostname.$implodedParts;
|
||||||
|
}
|
||||||
|
}
|
32
src/BeSimple/SoapClient/Xml/RemoteFileResolver.php
Normal file
32
src/BeSimple/SoapClient/Xml/RemoteFileResolver.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RemoteFileResolver
|
||||||
|
{
|
||||||
|
public static function instantiateResolver()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $wsdlPath File URL/path
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isRemoteFile($wsdlPath)
|
||||||
|
{
|
||||||
|
$parsedUrlOrFalse = @parse_url($wsdlPath);
|
||||||
|
if ($parsedUrlOrFalse !== false) {
|
||||||
|
if (isset($parsedUrlOrFalse['scheme']) && strpos($parsedUrlOrFalse['scheme'], 'http') === 0) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception('Could not determine wsdlPath is remote: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
}
|
60
src/BeSimple/SoapClient/Xml/XmlDomDocumentImportReplacer.php
Normal file
60
src/BeSimple/SoapClient/Xml/XmlDomDocumentImportReplacer.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\WsdlDownloader;
|
||||||
|
use BeSimple\SoapClient\Xml\Path\RelativePathResolver;
|
||||||
|
use DOMElement;
|
||||||
|
use DOMXPath;
|
||||||
|
|
||||||
|
class XmlDomDocumentImportReplacer
|
||||||
|
{
|
||||||
|
public static function instantiateReplacer()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateXmlDocument(
|
||||||
|
Curl $curl,
|
||||||
|
$cacheType,
|
||||||
|
DOMXPath $xpath,
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath = null
|
||||||
|
) {
|
||||||
|
$xpath->registerNamespace($schemaPrefix, $schemaUrl);
|
||||||
|
$nodes = $xpath->query('.//'.$schemaPrefix.':include | .//'.$schemaPrefix.':import');
|
||||||
|
if ($nodes->length > 0) {
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
/** @var DOMElement $node */
|
||||||
|
$locationPath = $node->getAttribute($locationAttributeName);
|
||||||
|
if ($locationPath !== '') {
|
||||||
|
if (RemoteFileResolver::instantiateResolver()->isRemoteFile($locationPath)) {
|
||||||
|
$node->setAttribute(
|
||||||
|
$locationAttributeName,
|
||||||
|
WsdlDownloader::instantiateDownloader()->getWsdlPath(
|
||||||
|
$curl,
|
||||||
|
$locationPath,
|
||||||
|
$cacheType,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} elseif ($parentFilePath !== null) {
|
||||||
|
$node->setAttribute(
|
||||||
|
$locationAttributeName,
|
||||||
|
WsdlDownloader::instantiateDownloader()->getWsdlPath(
|
||||||
|
$curl,
|
||||||
|
RelativePathResolver::instantiateResolver()
|
||||||
|
->resolveRelativePathInUrl($parentFilePath, $locationPath),
|
||||||
|
$cacheType,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
src/BeSimple/SoapClient/Xml/XmlFileDomDocumentProcessor.php
Normal file
77
src/BeSimple/SoapClient/Xml/XmlFileDomDocumentProcessor.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapCommon\Helper;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class XmlFileDomDocumentProcessor
|
||||||
|
{
|
||||||
|
public static function writeCacheFile(Curl $curl, $cacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile)
|
||||||
|
{
|
||||||
|
if ($isRemoteFile === true) {
|
||||||
|
$curlResponse = $curl->executeCurlWithCachedSession($wsdlPath);
|
||||||
|
if ($curlResponse->curlStatusSuccess()) {
|
||||||
|
if (mb_strlen($curlResponse->getResponseBody()) === 0) {
|
||||||
|
throw new Exception('Could not write WSDL cache file: empty curl response from: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
if ($resolveRemoteIncludes === true) {
|
||||||
|
$document = self::getXmlFileDomDocument($curl, $cacheType, $curlResponse->getResponseBody(), $wsdlPath);
|
||||||
|
self::saveXmlDomDocument($document, $cacheFilePath);
|
||||||
|
} else {
|
||||||
|
file_put_contents($cacheFilePath, $curlResponse->getResponseBody());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception('Could not write WSDL cache file: Download failed with message: '.$curlResponse->getCurlErrorMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (file_exists($wsdlPath)) {
|
||||||
|
$document = self::getXmlFileDomDocument($curl, $cacheType, file_get_contents($wsdlPath));
|
||||||
|
self::saveXmlDomDocument($document, $cacheFilePath);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Could write WSDL cache file: local file does not exist: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves remote WSDL/XSD includes within the WSDL files.
|
||||||
|
*
|
||||||
|
* @param Curl $curl
|
||||||
|
* @param int $cacheType
|
||||||
|
* @param string $xmlFileSource XML file contents
|
||||||
|
* @param boolean $parentFilePath Parent file name
|
||||||
|
* @return DOMDocument
|
||||||
|
*/
|
||||||
|
private static function getXmlFileDomDocument(Curl $curl, $cacheType, $xmlFileSource, $parentFilePath = null)
|
||||||
|
{
|
||||||
|
$document = new DOMDocument('1.0', 'utf-8');
|
||||||
|
if ($document->loadXML($xmlFileSource) === false) {
|
||||||
|
throw new Exception('Could not save downloaded WSDL cache: '.$xmlFileSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xpath = new DOMXPath($document);
|
||||||
|
$xmlDomDocumentImportReplacer = XmlDomDocumentImportReplacer::instantiateReplacer();
|
||||||
|
$xmlDomDocumentImportReplacer->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_WSDL, Helper::NS_WSDL, 'location', $parentFilePath);
|
||||||
|
$xmlDomDocumentImportReplacer->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA, 'schemaLocation', $parentFilePath);
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function saveXmlDomDocument(DOMDocument $document, $cacheFilePath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$xmlContents = $document->saveXML();
|
||||||
|
if ($xmlContents === '') {
|
||||||
|
throw new Exception('Could not write WSDL cache file: DOMDocument returned empty XML file');
|
||||||
|
}
|
||||||
|
file_put_contents($cacheFilePath, $xmlContents);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
unlink($cacheFilePath);
|
||||||
|
throw new Exception('Could not write WSDL cache file: save method returned error: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace BeSimple\SoapCommon\Definition\Type;
|
namespace BeSimple\SoapCommon\Definition\Type;
|
||||||
|
|
||||||
use BeSimple\SoapCommon\Classmap;
|
use BeSimple\SoapCommon\ClassMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Kerl <christian-kerl@web.de>
|
* @author Christian Kerl <christian-kerl@web.de>
|
||||||
@ -27,7 +27,7 @@ class TypeRepository
|
|||||||
|
|
||||||
protected $classmap;
|
protected $classmap;
|
||||||
|
|
||||||
public function __construct(Classmap $classmap = null)
|
public function __construct(ClassMap $classmap = null)
|
||||||
{
|
{
|
||||||
$this->classmap = $classmap;
|
$this->classmap = $classmap;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class TypeRepository
|
|||||||
$phpType = $type->getPhpType();
|
$phpType = $type->getPhpType();
|
||||||
|
|
||||||
$this->types[$phpType] = $type;
|
$this->types[$phpType] = $type;
|
||||||
$this->addClassmap($type->getXmlType(), $phpType);
|
$this->addClassMap($type->getXmlType(), $phpType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasType($type)
|
public function hasType($type)
|
||||||
@ -119,12 +119,12 @@ class TypeRepository
|
|||||||
return $match[1];
|
return $match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClassmap()
|
public function getClassMap()
|
||||||
{
|
{
|
||||||
return $this->classmap;
|
return $this->classmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addClassmap($xmlType, $phpType)
|
protected function addClassMap($xmlType, $phpType)
|
||||||
{
|
{
|
||||||
if (!$this->classmap) {
|
if (!$this->classmap) {
|
||||||
return;
|
return;
|
||||||
|
@ -27,7 +27,7 @@ class MimeBoundaryAnalyser
|
|||||||
*/
|
*/
|
||||||
public static function isMessageLineBoundary($mimeMessageLine)
|
public static function isMessageLineBoundary($mimeMessageLine)
|
||||||
{
|
{
|
||||||
return strlen($mimeMessageLine) > 0 && $mimeMessageLine[0] === "-";
|
return preg_match('/^--[0-9A-Za-z\s\'\/\+\_\,\-\.\:\=\?]+/', $mimeMessageLine) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ namespace BeSimple\SoapClient;
|
|||||||
|
|
||||||
use BeSimple\SoapClient\Curl\CurlOptions;
|
use BeSimple\SoapClient\Curl\CurlOptions;
|
||||||
use BeSimple\SoapClient\SoapOptions\SoapClientOptions;
|
use BeSimple\SoapClient\SoapOptions\SoapClientOptions;
|
||||||
|
use BeSimple\SoapClient\SoapServerAuthentication\SoapServerAuthenticationBasic;
|
||||||
use BeSimple\SoapCommon\ClassMap;
|
use BeSimple\SoapCommon\ClassMap;
|
||||||
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||||
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
||||||
@ -87,6 +88,27 @@ class SoapClientBuilderTest extends PHPUnit_Framework_TestCase
|
|||||||
self::assertInstanceOf(SoapClient::class, $soapClient);
|
self::assertInstanceOf(SoapClient::class, $soapClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateOptionsWithAuthenticationAndEndpointLocationAndSslVersionV3()
|
||||||
|
{
|
||||||
|
$authentication = new SoapServerAuthenticationBasic('', '');
|
||||||
|
$soapClientOptions = SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication);
|
||||||
|
|
||||||
|
self::assertSame(CURL_SSLVERSION_SSLv3, $soapClientOptions->getSslVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructSoapClientWithAuthenticationAndEndpointLocationAndSslVersionV3()
|
||||||
|
{
|
||||||
|
$authentication = new SoapServerAuthenticationBasic('', '');
|
||||||
|
$soapOptions = SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK);
|
||||||
|
|
||||||
|
$soapClient = $this->getSoapBuilder()->build(
|
||||||
|
SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication),
|
||||||
|
$soapOptions
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertInstanceOf(SoapClient::class, $soapClient);
|
||||||
|
}
|
||||||
|
|
||||||
private function getSoapBuilder()
|
private function getSoapBuilder()
|
||||||
{
|
{
|
||||||
return new SoapClientBuilder();
|
return new SoapClientBuilder();
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml\Path;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class RelativePathResolverTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/** @var RelativePathResolver */
|
||||||
|
private $relativePathResolver;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->relativePathResolver = new RelativePathResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $base
|
||||||
|
* @param string $relative
|
||||||
|
* @param string $assertPath
|
||||||
|
* @dataProvider providePathInfo
|
||||||
|
*/
|
||||||
|
public function testResolveRelativePathInUrl($base, $relative, $assertPath)
|
||||||
|
{
|
||||||
|
$path = $this->relativePathResolver->resolveRelativePathInUrl($base, $relative);
|
||||||
|
|
||||||
|
self::assertEquals($assertPath, $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providePathInfo()
|
||||||
|
{
|
||||||
|
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/',
|
||||||
|
'Document1.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document1.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/',
|
||||||
|
'../Schemas/Common/Document2.xsd',
|
||||||
|
'http://endpoint-location.ltd:8080/Schemas/Common/Document2.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd/',
|
||||||
|
'../Schemas/Common/Document3.xsd',
|
||||||
|
'http://endpoint-location.ltd/Schemas/Common/Document3.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd/',
|
||||||
|
'/Document4.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document4.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd',
|
||||||
|
'/Document5.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document5.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd',
|
||||||
|
'Document6.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document6.xsd',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class RemoteFileResolverTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
const FILE_IS_REMOTE = true;
|
||||||
|
const FILE_IS_NOT_REMOTE = false;
|
||||||
|
|
||||||
|
/** @var RemoteFileResolver */
|
||||||
|
private $remoteFileResolver;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->remoteFileResolver = new RemoteFileResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $wsdlPath
|
||||||
|
* @param bool $assertIsRemoteFile
|
||||||
|
* @dataProvider provideWsdlPaths
|
||||||
|
*/
|
||||||
|
public function testIsRemoteFile($wsdlPath, $assertIsRemoteFile)
|
||||||
|
{
|
||||||
|
$isRemoteFile = $this->remoteFileResolver->isRemoteFile($wsdlPath);
|
||||||
|
|
||||||
|
self::assertEquals($assertIsRemoteFile, $isRemoteFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideWsdlPaths()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['http://endpoint.tld/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||||
|
['http://endpoint.tld:1944/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||||
|
['path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
['../../path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
['/path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\Curl\CurlOptionsBuilder;
|
||||||
|
use BeSimple\SoapCommon\Cache;
|
||||||
|
use BeSimple\SoapCommon\Helper;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class XmlDomDocumentImportReplacerTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
const NO_PARENT_FILE_PATH = null;
|
||||||
|
|
||||||
|
/** @var XmlDomDocumentImportReplacer */
|
||||||
|
private $xmlDomDocumentImportReplacer;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->xmlDomDocumentImportReplacer = new XmlDomDocumentImportReplacer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $xmlSource
|
||||||
|
* @param Curl $curl
|
||||||
|
* @param string $schemaPrefix
|
||||||
|
* @param string $schemaUrl
|
||||||
|
* @param string $locationAttributeName
|
||||||
|
* @param string|null $parentFilePath
|
||||||
|
* @param string|null $assertImportXmlSource
|
||||||
|
* @dataProvider provideXmlDocumentData
|
||||||
|
*/
|
||||||
|
public function testUpdateXmlDocument(
|
||||||
|
$xmlSource,
|
||||||
|
Curl $curl,
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath = null,
|
||||||
|
$assertImportXmlSource = null
|
||||||
|
) {
|
||||||
|
$wsdl = new DOMDocument();
|
||||||
|
$wsdl->loadXML($xmlSource);
|
||||||
|
|
||||||
|
$this->xmlDomDocumentImportReplacer->updateXmlDocument(
|
||||||
|
$curl,
|
||||||
|
Cache::TYPE_NONE,
|
||||||
|
new DOMXPath($wsdl),
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath
|
||||||
|
);
|
||||||
|
$wsdlSource = $wsdl->saveHTML();
|
||||||
|
|
||||||
|
self::assertContains(
|
||||||
|
$assertImportXmlSource,
|
||||||
|
$wsdlSource
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideXmlDocumentData()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'wsdlWithoutParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_WSDL,
|
||||||
|
Helper::NS_WSDL,
|
||||||
|
'location',
|
||||||
|
self::NO_PARENT_FILE_PATH,
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'schemaWithoutParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_XML_SCHEMA,
|
||||||
|
Helper::NS_XML_SCHEMA,
|
||||||
|
'schemaLocation',
|
||||||
|
self::NO_PARENT_FILE_PATH,
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'wsdlWithParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_WSDL,
|
||||||
|
Helper::NS_WSDL,
|
||||||
|
'location',
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/',
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'schemaWithParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_XML_SCHEMA,
|
||||||
|
Helper::NS_XML_SCHEMA,
|
||||||
|
'schemaLocation',
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/wsdl.wsdl',
|
||||||
|
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'schemaWithParentPathAndSubDir' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_XML_SCHEMA,
|
||||||
|
Helper::NS_XML_SCHEMA,
|
||||||
|
'schemaLocation',
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/subdir/wsdl.wsdl',
|
||||||
|
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/endpoint/Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<wsdl:definitions
|
||||||
|
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||||
|
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
|
||||||
|
xmlns:ns="http://location.ltd/namespace1"
|
||||||
|
xmlns:ns2="http://location.ltd/namespace2"
|
||||||
|
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||||
|
xmlns:tns="http://endpoint-location.tld:7654/ws"
|
||||||
|
xmlns:xs="http://www.w3.org/2001/XMLSchema" name="PushServerWSDL"
|
||||||
|
targetNamespace="http://location.ltd/target-namespace">
|
||||||
|
<wsdl:types>
|
||||||
|
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace1">
|
||||||
|
<xs:include schemaLocation="../Schemas/Common/Document1.xsd"/>
|
||||||
|
</xs:schema>
|
||||||
|
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace2">
|
||||||
|
<xs:include schemaLocation="../Schemas/Common/Document2.xsd"/>
|
||||||
|
</xs:schema>
|
||||||
|
</wsdl:types>
|
||||||
|
<wsdl:message name="ServerHeader">
|
||||||
|
<wsdl:part element="ns:serverHeader" name="serverHeader"/>
|
||||||
|
</wsdl:message>
|
||||||
|
|
||||||
|
<wsdl:portType name="Server">
|
||||||
|
<wsdl:operation name="SendPushMessage">
|
||||||
|
<wsdl:documentation>TEST-OPERATION-1</wsdl:documentation>
|
||||||
|
<wsdl:input message="tns:SendPushMessageRequest" name="SendPushMessageRequest"/>
|
||||||
|
<wsdl:output message="tns:SendPushMessageResponse" name="SendPushMessageResponse"/>
|
||||||
|
<wsdl:fault message="tns:SystemFault" name="systemFault"/>
|
||||||
|
</wsdl:operation>
|
||||||
|
</wsdl:portType>
|
||||||
|
<wsdl:binding name="ServerBinding" type="tns:Server">
|
||||||
|
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||||
|
<wsdl:operation name="DummyMethod">
|
||||||
|
<soap:operation soapAction="http://endpoint-location.tld:7654/ep/v1" style="document"/>
|
||||||
|
<wsdl:input name="DummyMethodRequest">
|
||||||
|
<soap:body use="literal"/>
|
||||||
|
</wsdl:input>
|
||||||
|
<wsdl:output name="DummyMethodResponse">
|
||||||
|
<soap:body use="literal"/>
|
||||||
|
</wsdl:output>
|
||||||
|
<wsdl:fault name="soapServerFault">
|
||||||
|
<soap:fault name="soapServerFault" use="literal"/>
|
||||||
|
</wsdl:fault>
|
||||||
|
</wsdl:operation>
|
||||||
|
</wsdl:binding>
|
||||||
|
<wsdl:service name="ServerServices">
|
||||||
|
<wsdl:port binding="tns:ServerBinding" name="ServerServicesEndpoint">
|
||||||
|
<soap:address location="http://endpoint-location.tld:7654/ws/"/>
|
||||||
|
</wsdl:port>
|
||||||
|
</wsdl:service>
|
||||||
|
</wsdl:definitions>
|
@ -67,6 +67,8 @@ class MimeBoundaryAnalyserTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['-- this line is boundary', self::EXPECTED_IS_BOUNDARY],
|
['-- this line is boundary', self::EXPECTED_IS_BOUNDARY],
|
||||||
|
['--this line is boundary', self::EXPECTED_IS_BOUNDARY],
|
||||||
|
['--@ this line is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
|
||||||
['-- this line is also a boundary --', self::EXPECTED_IS_BOUNDARY],
|
['-- this line is also a boundary --', self::EXPECTED_IS_BOUNDARY],
|
||||||
['mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
|
['mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
|
||||||
[' -- mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
|
[' -- mesage line -- is not boundary', self::EXPECTED_IS_NOT_BOUNDARY],
|
||||||
|
Reference in New Issue
Block a user