Simplified the creation of WebServiceContext

This commit is contained in:
Francis Besset 2011-07-21 22:55:59 +02:00
parent c33005fed2
commit 9bd9677325
2 changed files with 31 additions and 30 deletions

View File

@ -25,10 +25,11 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
*/ */
class BeSimpleSoapExtension extends Extension class BeSimpleSoapExtension extends Extension
{ {
private $contextArguments;
// maps config options to service suffix // maps config options to service suffix
private $bindingConfigToServiceSuffixMap = array('rpc-literal' => '.rpcliteral', 'document-wrapped' => '.documentwrapped'); private $bindingConfigToServiceSuffixMap = array(
'rpc-literal' => 'rpcliteral',
'document-wrapped' => 'documentwrapped'
);
public function load(array $configs, ContainerBuilder $container) public function load(array $configs, ContainerBuilder $container)
{ {
@ -53,27 +54,14 @@ class BeSimpleSoapExtension extends Extension
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']]; $bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
unset($config['binding']); unset($config['binding']);
if (null === $this->contextArguments) {
$this->contextArguments = $container
->getDefinition('besimple.soap.context')
->getArguments()
;
}
$contextId = 'besimple.soap.context.'.$config['name']; $contextId = 'besimple.soap.context.'.$config['name'];
$context = $container->setDefinition($contextId, $definition = new DefinitionDecorator('besimple.soap.context')); $definition = new DefinitionDecorator('besimple.soap.context.'.$bindingSuffix);
$context = $container->setDefinition($contextId, $definition);
$arguments = array(); $options = $container
foreach($this->contextArguments as $i => $argument) { ->getDefinition('besimple.soap.context.'.$bindingSuffix)
if (in_array($i, array(1, 2, 3))) { ->getArgument(6);
$argument = new Reference($argument->__toString().$bindingSuffix);
} elseif (6 === $i) {
$argument = array_merge($argument, $config);
} else {
$argument = new Reference($argument->__toString());
}
$definition->replaceArgument($i, $argument); $definition->replaceArgument(6, array_merge($options, $config));
}
} }
} }

View File

@ -16,13 +16,26 @@
</parameters> </parameters>
<services> <services>
<service id="besimple.soap.context" class="%besimple.soap.context.class%" abstract="true"> <service id="besimple.soap.context.rpcliteral" class="%besimple.soap.context.class%" abstract="true">
<argument type="service" id="besimple.soap.definition.loader"/> <argument type="service" id="besimple.soap.definition.loader" />
<argument type="service" id="besimple.soap.definition.dumper.wsdl"/> <argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
<argument type="service" id="besimple.soap.binder.request"/> <argument type="service" id="besimple.soap.binder.request.rpcliteral" />
<argument type="service" id="besimple.soap.binder.response"/> <argument type="service" id="besimple.soap.binder.response.rpcliteral" />
<argument type="service" id="besimple.soap.type.repository"/> <argument type="service" id="besimple.soap.type.repository" />
<argument type="service" id="besimple.soap.converter.repository"/> <argument type="service" id="besimple.soap.converter.repository" />
<argument type="collection">
<argument key="cache_dir">%besimple.soap.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>
</argument>
</service>
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
<argument type="service" id="besimple.soap.definition.loader" />
<argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
<argument type="service" id="besimple.soap.binder.request.documentwrapped" />
<argument type="service" id="besimple.soap.binder.response.documentwrapped" />
<argument type="service" id="besimple.soap.type.repository" />
<argument type="service" id="besimple.soap.converter.repository" />
<argument type="collection"> <argument type="collection">
<argument key="cache_dir">%besimple.soap.cache_dir%</argument> <argument key="cache_dir">%besimple.soap.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument> <argument key="debug">%kernel.debug%</argument>