2010-10-04 20:27:00 +02:00
|
|
|
<?php
|
2010-10-05 21:44:30 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the WebServiceBundle.
|
|
|
|
*
|
|
|
|
* (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
|
|
|
|
|
|
|
namespace Bundle\WebServiceBundle\DependencyInjection;
|
|
|
|
|
2011-02-03 01:04:12 +01:00
|
|
|
use Bundle\WebServiceBundle\Util\Assert;
|
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
|
|
|
|
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;
|
2010-10-04 20:27:00 +02:00
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
|
|
|
|
2010-10-05 21:44:30 +02:00
|
|
|
/**
|
|
|
|
* WebServiceExtension.
|
|
|
|
*
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
2010-10-04 20:27:00 +02:00
|
|
|
class WebServiceExtension extends Extension
|
|
|
|
{
|
2011-04-08 00:45:52 +02:00
|
|
|
// maps config options to service suffix'
|
|
|
|
private $bindingConfigToServiceSuffixMap = array('rpc-literal' => '.rpcliteral', 'document-wrapped' => '.documentwrapped');
|
|
|
|
|
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-04-08 00:45:52 +02:00
|
|
|
$loader->load('annotations.xml');
|
2011-04-07 21:49:01 +02:00
|
|
|
$loader->load('webservice.xml');
|
|
|
|
|
|
|
|
$processor = new Processor();
|
|
|
|
$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);
|
|
|
|
|
|
|
|
foreach($config['services'] as $serviceContextConfig)
|
2010-10-08 14:24:42 +02:00
|
|
|
{
|
2011-04-07 21:49:01 +02:00
|
|
|
$this->createWebServiceContext($serviceContextConfig, $container);
|
2010-10-08 14:24:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 21:49:01 +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
|
|
|
$bindingDependendArguments = array(1, 3, 4);
|
|
|
|
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
|
|
|
|
unset($config['binding']);
|
|
|
|
|
|
|
|
$contextPrototype = $container->getDefinition('webservice.context');
|
|
|
|
$contextPrototypeArguments = $contextPrototype->getArguments();
|
2011-04-07 21:49:01 +02:00
|
|
|
|
2011-04-08 00:45:52 +02:00
|
|
|
$contextId = 'webservice.context.' . $config['name'];
|
|
|
|
$context = $container->setDefinition($contextId, new DefinitionDecorator('webservice.context'));
|
|
|
|
|
|
|
|
foreach($bindingDependendArguments as $idx)
|
|
|
|
{
|
|
|
|
$context->setArgument($idx, new Reference($contextPrototypeArguments[$idx] . $bindingSuffix));
|
|
|
|
}
|
|
|
|
$context->setArgument(5, array_merge($contextPrototypeArguments[5], $config));
|
2010-10-04 20:27:00 +02:00
|
|
|
}
|
2011-04-07 21:49:01 +02:00
|
|
|
|
2010-10-04 20:27:00 +02:00
|
|
|
public function getNamespace()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-04-07 21:49:01 +02:00
|
|
|
public function getXsdValidationBasePath()
|
2010-10-04 20:27:00 +02:00
|
|
|
{
|
2011-04-07 21:49:01 +02:00
|
|
|
return null;
|
2010-10-04 20:27:00 +02:00
|
|
|
}
|
|
|
|
}
|