[SoapBundle] Added configuration to configure client proxy

This commit is contained in:
Francis Besset 2014-08-18 13:54:19 +02:00
parent 1a7f60b679
commit 7a9119cef1
3 changed files with 55 additions and 4 deletions

View File

@ -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'])) { if (isset($defOptions['cache_type'])) {
$defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']); $defOptions['cache_type'] = $this->getCacheType($defOptions['cache_type']);
} }

View File

@ -24,6 +24,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class Configuration class Configuration
{ {
private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory'); private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory');
private $proxyAuth = array('basic', 'ntlm');
/** /**
* Generates the configuration tree. * Generates the configuration tree.
@ -85,12 +86,33 @@ class Configuration
->scalarNode('cache_type') ->scalarNode('cache_type')
->validate() ->validate()
->ifNotInArray($this->cacheTypes) ->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()
->end() ->end()
->arrayNode('classmap') ->arrayNode('classmap')
->useAttributeAsKey('name')->prototype('scalar')->end() ->useAttributeAsKey('name')->prototype('scalar')->end()
->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() ->end()
->end() ->end()

View File

@ -1,8 +1,8 @@
Configuration Configuration
============= =============
Minimal client configuration Client configuration
---------------------------- --------------------
Configure your first client in your config file: Configure your first client in your config file:
@ -12,8 +12,20 @@ Configure your first client in your config file:
be_simple_soap: be_simple_soap:
clients: clients:
DemoApi: 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 Using client
------------ ------------