From 63fda38f2aed27e3958161c53e1a2d8d44ce85c1 Mon Sep 17 00:00:00 2001 From: Marcos Fadul Date: Thu, 28 Apr 2016 10:38:35 -0300 Subject: [PATCH] Minor: Add configuration possibilities --- DependencyInjection/BeSimpleSoapExtension.php | 44 ++++++++++++++++++- DependencyInjection/Configuration.php | 28 ++++++++++++ Soap/SoapClientBuilder.php | 5 +++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/BeSimpleSoapExtension.php b/DependencyInjection/BeSimpleSoapExtension.php index ebb3623..7549bf9 100644 --- a/DependencyInjection/BeSimpleSoapExtension.php +++ b/DependencyInjection/BeSimpleSoapExtension.php @@ -97,7 +97,7 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co ->getDefinition('besimple.soap.client.builder') ->getArgument(1); - foreach (array('cache_type', 'user_agent') as $key) { + foreach (array('cache_type', 'user_agent', 'options') as $key) { if (isset($options[$key])) { $defOptions[$key] = $options[$key]; } @@ -120,10 +120,40 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co )); } + $authArray = $options['authentication']; + if (null !== $authArray) { + $type = $authArray['type']; + if ((null === $type || 'digest' == $type) + && $authArray['local_cert'] + ) { + $definition->addMethodCall( + 'withBasicAuthentication', + [ + $authArray['local_cert'], + $authArray['password'] + ] + ); + } elseif ((null === $type || 'basic' == $type) + && $authArray['login'] + ) { + $definition->addMethodCall( + 'withBasicAuthentication', + [ + $authArray['login'], + $authArray['password'] + ] + ); + } + } + if (isset($defOptions['cache_type'])) { $defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']); } + if (isset($defOptions['options']['soap_version'])) { + $defOptions['options']['soap_version'] = $this->getSoapVersion($defOptions['options']['soap_version']); + } + $definition->replaceArgument(1, $defOptions); $classmap = $this->createClientClassmap($client, $options['classmap'], $container); @@ -198,4 +228,16 @@ private function getCacheType($type) return Cache::TYPE_DISK_MEMORY; } } + + private function getSoapVersion($version) + { + switch ($version) { + + case 'soap_1_1': + return \SOAP_1_1; + break; + default: + return \SOAP_1_2; + } + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9374bff..711af0b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,6 +25,8 @@ class Configuration { private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory'); private $proxyAuth = array('basic', 'ntlm'); + private $authType = array('basic', 'digest'); + private $soapType = array('soap_1_1', 'soap_1_2'); /** * Generates the configuration tree. @@ -82,6 +84,32 @@ private function addClientSection(ArrayNodeDefinition $rootNode) ->prototype('array') ->children() ->scalarNode('wsdl')->isRequired()->end() + ->arrayNode('options') + ->children() + ->scalarNode('location')->defaultNull()->end() + ->scalarNode('uri')->defaultNull()->end() + ->scalarNode('soap_version') + ->validate() + ->ifNotInArray($this->soapType) + ->thenInvalid(sprintf('The soap type has to be either: %s', implode(', ', $this->authType))) + ->end() + ->end() + ->end() + ->end() + ->arrayNode('authentication') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('login')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() + ->scalarNode('local_cert')->defaultNull()->end() + ->scalarNode('type')->defaultNull() + ->validate() + ->ifNotInArray($this->authType) + ->thenInvalid(sprintf('The auth type has to be either: %s', implode(', ', $this->authType))) + ->end() + ->end() + ->end() + ->end() ->scalarNode('user_agent')->end() ->scalarNode('cache_type') ->validate() diff --git a/Soap/SoapClientBuilder.php b/Soap/SoapClientBuilder.php index 977b92b..4f2d0a9 100644 --- a/Soap/SoapClientBuilder.php +++ b/Soap/SoapClientBuilder.php @@ -21,6 +21,10 @@ public function __construct($wsdl, array $options, Classmap $classmap = null, Ty ->withTrace($options['debug']) ; + if (isset($options['options'])) { + $this->soapOptions = array_merge($this->soapOptions, $options['options']); + } + if (isset($options['user_agent'])) { $this->withUserAgent($options['user_agent']); } @@ -54,6 +58,7 @@ protected function checkOptions(array $options) 'cache_type' => null, 'exceptions' => true, 'user_agent' => 'BeSimpleSoap', + 'options' => array() ); // check option names and live merge, if errors are encountered Exception will be thrown