diff --git a/DependencyInjection/BeSimpleSoapExtension.php b/DependencyInjection/BeSimpleSoapExtension.php
index c462bca..62fc3aa 100644
--- a/DependencyInjection/BeSimpleSoapExtension.php
+++ b/DependencyInjection/BeSimpleSoapExtension.php
@@ -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']];
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 658a283..c56f3c9 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -74,7 +74,6 @@ class Configuration
->prototype('array')
->children()
->scalarNode('wsdl')->isRequired()->end()
- ->scalarNode('namespace')->end()
->scalarNode('user_agent')->end()
->scalarNode('cache_type')
->validate()
diff --git a/Resources/config/client.xml b/Resources/config/client.xml
index 7ea688b..939e470 100644
--- a/Resources/config/client.xml
+++ b/Resources/config/client.xml
@@ -4,12 +4,12 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
- BeSimple\SoapClient\SoapClient
+ BeSimple\SoapBundle\Soap\SoapClientBuilder
BeSimple\SoapCommon\Classmap
-
+
%kernel.debug%
@@ -19,6 +19,8 @@
+
+
diff --git a/Soap/SoapClientBuilder.php b/Soap/SoapClientBuilder.php
new file mode 100644
index 0000000..c21993f
--- /dev/null
+++ b/Soap/SoapClientBuilder.php
@@ -0,0 +1,77 @@
+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)
+ ));
+ }
+ }
+}
\ No newline at end of file