Replaced soap.client by soap.client.builder
This commit is contained in:
parent
6d2e9d7634
commit
d3c31116c7
@ -79,23 +79,23 @@ class BeSimpleSoapExtension extends Extension
|
||||
$loader->load('client.xml');
|
||||
|
||||
foreach ($config as $client => $options) {
|
||||
$definition = new DefinitionDecorator('besimple.soap.client');
|
||||
$context = $container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
|
||||
$definition = new DefinitionDecorator('besimple.soap.client.builder');
|
||||
$context = $container->setDefinition(sprintf('besimple.soap.client.builder.%s', $client), $definition);
|
||||
|
||||
$definition->replaceArgument(0, $options['wsdl']);
|
||||
|
||||
$defOptions = $container
|
||||
->getDefinition('besimple.soap.client')
|
||||
->getDefinition('besimple.soap.client.builder')
|
||||
->getArgument(1);
|
||||
|
||||
foreach (array('cache_type', 'namespace', 'user_agent') as $key) {
|
||||
foreach (array('cache_type', 'user_agent') as $key) {
|
||||
if (isset($options[$key])) {
|
||||
$defOptions[$key] = $options[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($defOptions['cache_type'])) {
|
||||
$$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
|
||||
$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
|
||||
}
|
||||
|
||||
$definition->replaceArgument(1, $defOptions);
|
||||
@ -106,6 +106,8 @@ class BeSimpleSoapExtension extends Extension
|
||||
} else {
|
||||
$definition->replaceArgument(2, null);
|
||||
}
|
||||
|
||||
$this->createClient($client, $container);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +123,14 @@ class BeSimpleSoapExtension extends Extension
|
||||
return sprintf('besimple.soap.classmap.%s', $client);
|
||||
}
|
||||
|
||||
private function createClient($client, ContainerBuilder $container)
|
||||
{
|
||||
$definition = new DefinitionDecorator('besimple.soap.client');
|
||||
$context = $container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
|
||||
|
||||
$definition->setFactoryService(sprintf('besimple.soap.client.builder.%s', $client));
|
||||
}
|
||||
|
||||
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
|
||||
|
@ -74,7 +74,6 @@ class Configuration
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('wsdl')->isRequired()->end()
|
||||
->scalarNode('namespace')->end()
|
||||
->scalarNode('user_agent')->end()
|
||||
->scalarNode('cache_type')
|
||||
->validate()
|
||||
|
@ -4,12 +4,12 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="besimple.soap.client.class">BeSimple\SoapClient\SoapClient</parameter>
|
||||
<parameter key="besimple.soap.client.builder.class">BeSimple\SoapBundle\Soap\SoapClientBuilder</parameter>
|
||||
<parameter key="besimple.soap.classmap.class">BeSimple\SoapCommon\Classmap</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="besimple.soap.client" class="%besimple.soap.client.class%" abstract="true">
|
||||
<service id="besimple.soap.client.builder" class="%besimple.soap.client.builder.class%" abstract="true">
|
||||
<argument /> <!-- wsdl URI -->
|
||||
<argument type="collection">
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
@ -19,6 +19,8 @@
|
||||
<argument type="service" id="besimple.soap.cache" />
|
||||
</service>
|
||||
|
||||
<service id="besimple.soap.client" factory-service="besimple.soap.client.builder" factory-method="build" class="%besimple.soap.client.builder.class%" abstract="true" />
|
||||
|
||||
<service id="besimple.soap.classmap" class="%besimple.soap.classmap.class%" abstract="true" />
|
||||
</services>
|
||||
|
||||
|
77
Soap/SoapClientBuilder.php
Normal file
77
Soap/SoapClientBuilder.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
use BeSimple\SoapCommon\Classmap;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||
use BeSimple\SoapClient\SoapClientBuilder as BaseSoapClientBuilder;
|
||||
|
||||
class SoapClientBuilder extends BaseSoapClientBuilder
|
||||
{
|
||||
protected $soapClient;
|
||||
|
||||
public function __construct($wsdl, array $options, Classmap $classmap = null, TypeConverterCollection $converters = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->checkOptions($options);
|
||||
|
||||
$this
|
||||
->withWsdl($wsdl)
|
||||
->withTrace($options['debug'])
|
||||
;
|
||||
|
||||
if (isset($options['user_agent'])) {
|
||||
$this->withUserAgent($options['user_agent']);
|
||||
}
|
||||
|
||||
if (isset($options['cache_type'])) {
|
||||
$this->withWsdlCache($options['cache_type']);
|
||||
}
|
||||
|
||||
if ($classmap) {
|
||||
$this->withClassmap($classmap);
|
||||
}
|
||||
|
||||
if ($converters) {
|
||||
$this->withTypeConverters($converters);
|
||||
}
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
if (!$this->soapClient) {
|
||||
$this->soapClient = parent::build();
|
||||
}
|
||||
|
||||
return $this->soapClient;
|
||||
}
|
||||
|
||||
protected function checkOptions(array $options)
|
||||
{
|
||||
$checkOptions = array(
|
||||
'debug' => false,
|
||||
'cache_type' => null,
|
||||
'exceptions' => true,
|
||||
'user_agent' => 'BeSimpleSoap',
|
||||
);
|
||||
|
||||
// check option names and live merge, if errors are encountered Exception will be thrown
|
||||
$invalid = array();
|
||||
$isInvalid = false;
|
||||
foreach ($options as $key => $value) {
|
||||
if (!array_key_exists($key, $checkOptions)) {
|
||||
$isInvalid = true;
|
||||
$invalid[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInvalid) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "%s" class does not support the following options: "%s".',
|
||||
get_class($this),
|
||||
implode('\', \'', $invalid)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user