Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Add configuration possibilities #110

Open
wants to merge 1 commit into
base: 0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion DependencyInjection/BeSimpleSoapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
28 changes: 28 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions Soap/SoapClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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
Expand Down