2010-10-04 20:27:00 +02:00
|
|
|
<?php
|
2010-10-05 21:44:30 +02:00
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2010-10-05 21:44:30 +02:00
|
|
|
*
|
|
|
|
* (c) Christian Kerl <christian-kerl@web.de>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
2010-10-04 20:27:00 +02:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\DependencyInjection;
|
2010-10-04 20:27:00 +02:00
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
2011-07-17 10:46:54 +02:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
2010-10-04 20:27:00 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-04-08 00:45:52 +02:00
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
2010-10-05 21:44:30 +02:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
2011-04-07 21:49:01 +02:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
|
|
|
|
2010-10-05 21:44:30 +02:00
|
|
|
/**
|
2011-07-18 22:43:12 +02:00
|
|
|
* BeSimpleSoapExtension.
|
2010-10-05 21:44:30 +02:00
|
|
|
*
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
2011-07-18 22:43:12 +02:00
|
|
|
class BeSimpleSoapExtension extends Extension
|
2010-10-04 20:27:00 +02:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
private $contextArguments;
|
|
|
|
|
2011-07-18 22:59:20 +02:00
|
|
|
// maps config options to service suffix
|
2011-04-08 00:45:52 +02:00
|
|
|
private $bindingConfigToServiceSuffixMap = array('rpc-literal' => '.rpcliteral', 'document-wrapped' => '.documentwrapped');
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
2010-10-07 15:16:56 +02:00
|
|
|
{
|
2011-04-07 21:49:01 +02:00
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
$loader->load('loaders.xml');
|
2011-04-07 21:49:01 +02:00
|
|
|
$loader->load('webservice.xml');
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
$processor = new Processor();
|
2011-04-07 21:49:01 +02:00
|
|
|
$configuration = new Configuration();
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
$config = $processor->process($configuration->getConfigTree(), $configs);
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-14 18:39:47 +02:00
|
|
|
foreach($config['services'] as $name => $serviceConfig) {
|
2011-07-17 10:46:54 +02:00
|
|
|
$serviceConfig['name'] = $name;
|
|
|
|
$this->createWebServiceContext($serviceConfig, $container);
|
2010-10-08 14:24:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
2010-10-04 20:27:00 +02:00
|
|
|
{
|
2011-04-08 00:45:52 +02:00
|
|
|
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
|
|
|
|
unset($config['binding']);
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
if (null === $this->contextArguments) {
|
|
|
|
$this->contextArguments = $container
|
2011-07-18 22:59:20 +02:00
|
|
|
->getDefinition('besimple.soap.context')
|
2011-07-17 10:46:54 +02:00
|
|
|
->getArguments()
|
|
|
|
;
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-18 22:59:20 +02:00
|
|
|
$contextId = 'besimple.soap.context.'.$config['name'];
|
|
|
|
$context = $container->setDefinition($contextId, $definition = new DefinitionDecorator('besimple.soap.context'));
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-14 18:13:34 +02:00
|
|
|
$arguments = array();
|
2011-07-17 10:46:54 +02:00
|
|
|
foreach($this->contextArguments as $i => $argument) {
|
2011-07-17 15:08:46 +02:00
|
|
|
if (in_array($i, array(1, 2, 3))) {
|
2011-07-17 10:46:54 +02:00
|
|
|
$argument = new Reference($argument->__toString().$bindingSuffix);
|
2011-07-17 15:08:46 +02:00
|
|
|
} elseif (6 === $i) {
|
2011-07-17 10:46:54 +02:00
|
|
|
$argument = array_merge($argument, $config);
|
|
|
|
} else {
|
|
|
|
$argument = new Reference($argument->__toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
$definition->replaceArgument($i, $argument);
|
2011-04-08 00:45:52 +02:00
|
|
|
}
|
2010-10-04 20:27:00 +02:00
|
|
|
}
|
2011-07-18 22:43:12 +02:00
|
|
|
}
|