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
{
private $contextArguments;
// 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)
{
@ -53,27 +54,14 @@ class BeSimpleSoapExtension extends Extension
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
unset($config['binding']);
if (null === $this->contextArguments) {
$this->contextArguments = $container
->getDefinition('besimple.soap.context')
->getArguments()
;
}
$contextId = 'besimple.soap.context.'.$config['name'];
$definition = new DefinitionDecorator('besimple.soap.context.'.$bindingSuffix);
$context = $container->setDefinition($contextId, $definition);
$contextId = 'besimple.soap.context.'.$config['name'];
$context = $container->setDefinition($contextId, $definition = new DefinitionDecorator('besimple.soap.context'));
$options = $container
->getDefinition('besimple.soap.context.'.$bindingSuffix)
->getArgument(6);
$arguments = array();
foreach($this->contextArguments as $i => $argument) {
if (in_array($i, array(1, 2, 3))) {
$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>
<services>
<service id="besimple.soap.context" class="%besimple.soap.context.class%" abstract="true">
<argument type="service" id="besimple.soap.definition.loader"/>
<argument type="service" id="besimple.soap.definition.dumper.wsdl"/>
<argument type="service" id="besimple.soap.binder.request"/>
<argument type="service" id="besimple.soap.binder.response"/>
<argument type="service" id="besimple.soap.type.repository"/>
<argument type="service" id="besimple.soap.converter.repository"/>
<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.dumper.wsdl.rpcliteral" />
<argument type="service" id="besimple.soap.binder.request.rpcliteral" />
<argument type="service" id="besimple.soap.binder.response.rpcliteral" />
<argument type="service" id="besimple.soap.type.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 key="cache_dir">%besimple.soap.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>