From ff6eca48ee4a36d29d0bf9ccae8d93c830b115cb Mon Sep 17 00:00:00 2001 From: Christian Kerl Date: Thu, 7 Apr 2011 21:49:01 +0200 Subject: [PATCH] reimplemented DI extension classes and DI container config; --- DependencyInjection/Configuration.php | 26 ++++++- DependencyInjection/WebServiceExtension.php | 79 ++++++--------------- Resources/config/webservice.xml | 72 +++++++++---------- 3 files changed, 81 insertions(+), 96 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 43667cb..3939b3e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() ; diff --git a/DependencyInjection/WebServiceExtension.php b/DependencyInjection/WebServiceExtension.php index 95dcb33..82e82c5 100644 --- a/DependencyInjection/WebServiceExtension.php +++ b/DependencyInjection/WebServiceExtension.php @@ -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,78 +27,35 @@ 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'); + + $processor = new Processor(); + $configuration = new Configuration(); - if(isset($config['definition'])) + $config = $processor->process($configuration->getConfigTree(), $configs); + + foreach($config['services'] as $serviceContextConfig) { - $this->registerServiceDefinitionConfig($config['definition'], $configuration); - } - else - { - throw new \InvalidArgumentException(); - } - - if(isset($config['binding'])) - { - $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) + + public function getNamespace() { - $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; - } + return null; } public function getXsdValidationBasePath() { return null; } - - public function getNamespace() - { - return null; - } - - public function getAlias() - { - return 'webservice'; - } } \ No newline at end of file diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index ba52356..b847f09 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -1,58 +1,58 @@ - + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Bundle\WebServiceBundle\Soap\SoapRequest - - Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder - Bundle\WebServiceBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder - - Bundle\WebServiceBundle\ServiceDefinition\ServiceDefinition - Bundle\WebServiceBundle\ServiceDefinition\Loader\XmlFileLoader - Bundle\WebServiceBundle\ServiceDefinition\Dumper\WsdlFileDumper + %kernel.cache_dir%/webservice - - - + + - - - - - + + + + + + + + + %webservice.cache_dir% + - - - - - - - - + + + + - - - %webservice.definition.name% - %webservice.definition.namespace% - + + + +