reimplemented DI extension classes and DI container config;
This commit is contained in:
parent
cf5665a502
commit
ff6eca48ee
|
@ -28,10 +28,34 @@ class Configuration
|
|||
public function getConfigTree()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('webservice');
|
||||
$rootNode = $treeBuilder->root('web_service');
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('services')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('name')
|
||||
->isRequired()
|
||||
->end()
|
||||
->scalarNode('namespace')
|
||||
->isRequired()
|
||||
->end()
|
||||
->scalarNode('resource')
|
||||
->defaultValue('*')
|
||||
->end()
|
||||
->scalarNode('resource_type')
|
||||
->defaultValue('annotation')
|
||||
->end()
|
||||
->scalarNode('binding')
|
||||
->defaultValue('document-wrapped')
|
||||
->validate()
|
||||
->ifNotInArray(array('rpc-literal', 'document-wrapped'))
|
||||
->thenInvalid("Service binding style has to be either 'rpc-literal' or 'document-wrapped'")
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
|
|
|
@ -12,10 +12,14 @@ namespace Bundle\WebServiceBundle\DependencyInjection;
|
|||
|
||||
use Bundle\WebServiceBundle\Util\Assert;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* WebServiceExtension.
|
||||
*
|
||||
|
@ -23,69 +27,26 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|||
*/
|
||||
class WebServiceExtension extends Extension
|
||||
{
|
||||
public function configLoad(array $config, ContainerBuilder $configuration)
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
if(!$configuration->hasDefinition('webservice.kernel'))
|
||||
{
|
||||
$loader = new XmlFileLoader($configuration, __DIR__ . '/../Resources/config');
|
||||
$loader->load('services.xml');
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$configuration->setAlias('http_kernel', 'webservice.kernel');
|
||||
}
|
||||
$loader->load('webservice.xml');
|
||||
|
||||
if(isset($config['definition']))
|
||||
{
|
||||
$this->registerServiceDefinitionConfig($config['definition'], $configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
$processor = new Processor();
|
||||
$configuration = new Configuration();
|
||||
|
||||
if(isset($config['binding']))
|
||||
$config = $processor->process($configuration->getConfigTree(), $configs);
|
||||
|
||||
foreach($config['services'] as $serviceContextConfig)
|
||||
{
|
||||
$this->registerServiceBindingConfig($config['binding'], $configuration);
|
||||
$this->createWebServiceContext($serviceContextConfig, $container);
|
||||
}
|
||||
}
|
||||
|
||||
protected function registerServiceDefinitionConfig(array $config, ContainerBuilder $configuration)
|
||||
private function createWebServiceContext(array $config, ContainerBuilder $container)
|
||||
{
|
||||
Assert::thatArgument('config.name', isset($config['name']));
|
||||
Assert::thatArgument('config.namespace', isset($config['namespace']));
|
||||
|
||||
$configuration->setParameter('webservice.definition.name', $config['name']);
|
||||
$configuration->setParameter('webservice.definition.namespace', $config['namespace']);
|
||||
$configuration->setParameter('webservice.definition.resource', isset($config['resource']) ? $config['resource'] : null);
|
||||
$configuration->setParameter('webservice.definition.wsdl', isset($config['wsdl']) ? $config['wsdl'] : null);
|
||||
}
|
||||
|
||||
protected function registerServiceBindingConfig(array $config, ContainerBuilder $configuration)
|
||||
{
|
||||
$style = isset($config['style']) ? $config['style'] : 'document-literal-wrapped';
|
||||
|
||||
if(!in_array($style, array('document-literal-wrapped', 'rpc-literal')))
|
||||
{
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$binderNamespace = 'Bundle\\WebServiceBundle\\ServiceBinding\\';
|
||||
|
||||
switch ($style)
|
||||
{
|
||||
case 'document-literal-wrapped':
|
||||
$configuration->setParameter('webservice.binder.request.class', $binderNamespace . 'DocumentLiteralWrappedRequestMessageBinder');
|
||||
$configuration->setParameter('webservice.binder.response.class', $binderNamespace . 'DocumentLiteralWrappedResponseMessageBinder');
|
||||
break;
|
||||
case 'rpc-literal':
|
||||
$configuration->setParameter('webservice.binder.request.class', $binderNamespace . 'RpcLiteralRequestMessageBinder');
|
||||
$configuration->setParameter('webservice.binder.response.class', $binderNamespace . 'RpcLiteralResponseMessageBinder');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
|
@ -93,8 +54,8 @@ class WebServiceExtension extends Extension
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getAlias()
|
||||
public function getXsdValidationBasePath()
|
||||
{
|
||||
return 'webservice';
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<container xmlns="http://www.symfony-project.org/schema/dic/services"
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="request.class">Bundle\WebServiceBundle\Soap\SoapRequest</parameter>
|
||||
|
||||
<parameter key="webservice.binder.request.class">Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder</parameter>
|
||||
<parameter key="webservice.binder.response.class">Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
||||
|
||||
<parameter key="webservice.definition.class">Bundle\WebServiceBundle\ServiceDefinition\ServiceDefinition</parameter>
|
||||
<parameter key="webservice.definition.loader.class">Bundle\WebServiceBundle\ServiceDefinition\Loader\XmlFileLoader</parameter>
|
||||
<parameter key="webservice.definition.dumper.class">Bundle\WebServiceBundle\ServiceDefinition\Dumper\WsdlFileDumper</parameter>
|
||||
<parameter key="webservice.cache_dir">%kernel.cache_dir%/webservice</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="webservice_controller" class="Bundle\WebServiceBundle\Controller\SoapWebServiceController">
|
||||
<argument type="service" id="webservice.binder" />
|
||||
<argument type="service" id="webservice.server.factory" />
|
||||
<service id="webservice.controller" class="Bundle\WebServiceBundle\Controller\SoapWebServiceController">
|
||||
<argument type="service" id="service_container" />
|
||||
<argument type="service" id="http_kernel" />
|
||||
</service>
|
||||
|
||||
<service id="webservice.binder" class="Bundle\WebServiceBundle\ServiceBinding\ServiceBinder">
|
||||
<argument type="service" id="webservice.definition" />
|
||||
|
||||
<service id="webservice.context" class="Bundle\WebServiceBundle\WebServiceContext" abstract="true">
|
||||
<argument type="service" id="webservice.definition.loader"/>
|
||||
<argument type="service" id="webservice.definition.dumper.wsdl"/>
|
||||
<argument type="service" id="webservice.converter.repository"/>
|
||||
<argument type="service" id="webservice.binder.request"/>
|
||||
<argument type="service" id="webservice.binder.response"/>
|
||||
<argument type="collection">
|
||||
<!--
|
||||
<argument key="name">%webservice.name%</argument>
|
||||
<argument key="namespace">%webservice.namespace%</argument>
|
||||
|
||||
<argument key="resource">%webservice.resource%</argument>
|
||||
<argument key="resource_type">%webservice.resource_type%</argument>
|
||||
-->
|
||||
<argument key="cache_dir">%webservice.cache_dir%</argument>
|
||||
</argument>
|
||||
</service>
|
||||
|
||||
<service id="webservice.binder.request" class="%webservice.binder.request.class%" />
|
||||
<service id="webservice.binder.response" class="%webservice.binder.response.class%" />
|
||||
|
||||
<service id="webservice.server.factory" class="Bundle\WebServiceBundle\Soap\SoapServerFactory">
|
||||
<argument type="service" id="webservice.definition" />
|
||||
<argument type="service" id="webservice.converter.repository" />
|
||||
<argument type="service" id="webservice.definition.dumper" />
|
||||
</service>
|
||||
<service id="webservice.binder.request.rpcliteral" class="Bundle\WebServiceBundle\ServiceBinding\RpcLiteralRequestMessageBinder" />
|
||||
<service id="webservice.binder.response.rpcliteral" class="Bundle\WebServiceBundle\ServiceBinding\RpcLiteralResponseMessageBinder" />
|
||||
<service id="webservice.binder.request.documentwrapped" class="Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder" />
|
||||
<service id="webservice.binder.response.documentwrapped" class="Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder" />
|
||||
|
||||
<service id="webservice.converter.repository" class="Bundle\WebServiceBundle\Converter\ConverterRepository">
|
||||
<call method="registerTypeConverterServices">
|
||||
<argument type="service" id="service_container" />
|
||||
</call>
|
||||
</service>
|
||||
<!--
|
||||
<service id="webservice.definition.loader" class="">
|
||||
|
||||
<service id="webservice.definition" class="%webservice.definition.class%" shared="true">
|
||||
<argument type="string">%webservice.definition.name%</argument>
|
||||
<argument type="string">%webservice.definition.namespace%</argument>
|
||||
<configurator service="webservice.definition.loader" method="loadServiceDefinition" />
|
||||
</service>
|
||||
<service id="webservice.definition.loader" class="%webservice.definition.loader.class%">
|
||||
<argument type="string">%webservice.definition.resource%</argument>
|
||||
-->
|
||||
<service id="webservice.definition.dumper.wsdl.rpcliteral" class="Bundle\WebServiceBundle\ServiceDefinition\Dumper\WsdlDumpler">
|
||||
|
||||
</service>
|
||||
<service id="webservice.definition.dumper" class="%webservice.definition.dumper.class%">
|
||||
<argument type="string">%webservice.definition.wsdl%</argument>
|
||||
<!--
|
||||
<service id="webservice.definition.dumper.wsdl.documentwrapped" class="">
|
||||
|
||||
</service>
|
||||
-->
|
||||
</services>
|
||||
</container>
|
||||
|
|
Loading…
Reference in New Issue