Get basic bundle configuration working for SoapClient with Symfony 3.x.
This commit is contained in:
parent
073028f160
commit
69a7005c35
|
@ -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');
|
||||||
|
@ -54,7 +57,7 @@ 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>
|
||||||
|
|
|
@ -4,17 +4,28 @@
|
||||||
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>
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue