From 7a9119cef107345824785bf5fadcf8342f436917 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 18 Aug 2014 13:54:19 +0200 Subject: [PATCH] [SoapBundle] Added configuration to configure client proxy --- .../BeSimpleSoapExtension.php | 17 +++++++++++++ .../DependencyInjection/Configuration.php | 24 ++++++++++++++++++- .../doc/soapclient/configuration.rst | 18 +++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php b/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php index 5de74a3..a0b8c51 100644 --- a/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php +++ b/src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php @@ -98,6 +98,23 @@ class BeSimpleSoapExtension extends Extension } } + $proxy = $options['proxy']; + if (false !== $proxy['host']) { + if (null !== $proxy['auth']) { + if ('basic' === $proxy['auth']) { + $proxy['auth'] = \CURLAUTH_BASIC; + } elseif ('ntlm' === $proxy['auth']) { + $proxy['auth'] = \CURLAUTH_NTLM; + } + } + + $definition->addMethodCall('withProxy', array( + $proxy['host'], $proxy['port'], + $proxy['login'], $proxy['password'], + $proxy['auth'] + )); + } + if (isset($defOptions['cache_type'])) { $defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']); } diff --git a/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php b/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php index 1cba9ff..9374bff 100644 --- a/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php +++ b/src/BeSimple/SoapBundle/DependencyInjection/Configuration.php @@ -24,6 +24,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; class Configuration { private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory'); + private $proxyAuth = array('basic', 'ntlm'); /** * Generates the configuration tree. @@ -85,12 +86,33 @@ class Configuration ->scalarNode('cache_type') ->validate() ->ifNotInArray($this->cacheTypes) - ->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() ->arrayNode('classmap') ->useAttributeAsKey('name')->prototype('scalar')->end() ->end() + ->arrayNode('proxy') + ->info('proxy configuration') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !is_array($v); }) + ->then(function ($v) { return array('host' => null === $v ? false : $v); }) + ->end() + ->children() + ->scalarNode('host')->defaultFalse()->end() + ->scalarNode('port')->defaultValue(3128)->end() + ->scalarNode('login')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() + ->scalarNode('auth') + ->defaultNull() + ->validate() + ->ifNotInArray($this->proxyAuth) + ->thenInvalid(sprintf('The proxy auth has to be either: %s', implode(', ', $this->proxyAuth))) + ->end() + ->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst index bd715a4..59088cc 100644 --- a/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst +++ b/src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst @@ -1,8 +1,8 @@ Configuration ============= -Minimal client configuration ----------------------------- +Client configuration +-------------------- Configure your first client in your config file: @@ -12,8 +12,20 @@ Configure your first client in your config file: be_simple_soap: clients: DemoApi: - wsdl: http://localhost:8086/app_dev.php/ws/DemoApi?wsdl + # required + wsdl: http://localhost/app_dev.php/ws/DemoApi?wsdl + # classmap (optional) + classmap: + type_name: "Full\Class\Name" + + # proxy (optional) + proxy: + host: proxy.domain.name # required to enable proxy configuration + port: 3128 + login: ~ + password: ~ + auth: ~ # can be 'basic' or 'ntlm' Using client ------------