From 0e177bd067184dd01422e54531aa2ab61e5f5ee0 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 14 Aug 2011 21:59:03 +0200 Subject: [PATCH] Moved stylesheet option in WsdlDumper service and add the possibility to configure --- DependencyInjection/BeSimpleSoapExtension.php | 2 ++ DependencyInjection/Configuration.php | 25 +++++++++++++++++-- Resources/config/webservice.xml | 3 +++ ServiceDefinition/Dumper/DumperInterface.php | 2 +- ServiceDefinition/Dumper/WsdlDumper.php | 17 +++++++------ WebServiceContext.php | 2 +- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/DependencyInjection/BeSimpleSoapExtension.php b/DependencyInjection/BeSimpleSoapExtension.php index faeb6bf..15a92d1 100644 --- a/DependencyInjection/BeSimpleSoapExtension.php +++ b/DependencyInjection/BeSimpleSoapExtension.php @@ -43,6 +43,8 @@ class BeSimpleSoapExtension extends Extension $config = $processor->process($configuration->getConfigTree(), $configs); + $container->setParameter('besimple.soap.definition.dumper.options.stylesheet', $config['wsdl_dumper']['stylesheet']); + foreach($config['services'] as $name => $serviceConfig) { $serviceConfig['name'] = $name; $this->createWebServiceContext($serviceConfig, $container); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ded0ae1..0f538cc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -10,6 +10,7 @@ namespace BeSimple\SoapBundle\DependencyInjection; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; /** @@ -27,8 +28,16 @@ class Configuration public function getConfigTree() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('web_service'); + $rootNode = $treeBuilder->root('be_simple_soap'); + $this->addServicesSection($rootNode); + $this->addWsdlDumperSection($rootNode); + + return $treeBuilder->buildTree(); + } + + private function addServicesSection(ArrayNodeDefinition $rootNode) + { $rootNode ->children() ->arrayNode('services') @@ -55,7 +64,19 @@ class Configuration ->end() ->end() ; + } - return $treeBuilder->buildTree(); + private function addWsdlDumperSection(ArrayNodeDefinition $rootNode) + { + $rootNode + ->children() + ->arrayNode('wsdl_dumper') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('stylesheet')->defaultNull() + ->end() + ->end() + ->end() + ; } } \ No newline at end of file diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index 5b7798f..b4e0b24 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -44,6 +44,9 @@ + + %besimple.soap.definition.dumper.options.stylesheet% + diff --git a/ServiceDefinition/Dumper/DumperInterface.php b/ServiceDefinition/Dumper/DumperInterface.php index e1dcb11..3b8b257 100644 --- a/ServiceDefinition/Dumper/DumperInterface.php +++ b/ServiceDefinition/Dumper/DumperInterface.php @@ -14,5 +14,5 @@ use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition; interface DumperInterface { - function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()); + function dumpServiceDefinition(ServiceDefinition $definition, $endpoint); } \ No newline at end of file diff --git a/ServiceDefinition/Dumper/WsdlDumper.php b/ServiceDefinition/Dumper/WsdlDumper.php index 7c07064..4653923 100644 --- a/ServiceDefinition/Dumper/WsdlDumper.php +++ b/ServiceDefinition/Dumper/WsdlDumper.php @@ -25,27 +25,28 @@ use Zend\Soap\Wsdl; class WsdlDumper implements DumperInterface { private $loader; + private $options; + private $wsdl; private $definition; - public function __construct(AnnotationComplexTypeLoader $loader) + public function __construct(AnnotationComplexTypeLoader $loader, array $options) { - $this->loader = $loader; + $this->loader = $loader; + $this->options = $options; } - public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()) + public function dumpServiceDefinition(ServiceDefinition $definition, $endpoint) { Assert::thatArgumentNotNull('definition', $definition); - $options = array_merge(array('endpoint' => '', 'stylesheet' => null), $options); - $this->definition = $definition; $this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition)); $port = $this->wsdl->addPortType($this->getPortTypeName()); $binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName())); $this->wsdl->addSoapBinding($binding, 'rpc'); - $this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $options['endpoint']); + $this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $endpoint); foreach ($definition->getMethods() as $method) { $requestParts = array(); @@ -87,8 +88,8 @@ class WsdlDumper implements DumperInterface $dom = $this->wsdl->toDomDocument(); $dom->formatOutput = true; - if (null !== $options['stylesheet']) { - $stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $options['stylesheet'])); + if ($this->options['stylesheet']) { + $stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet'])); $dom->insertBefore($stylesheet, $dom->documentElement); } diff --git a/WebServiceContext.php b/WebServiceContext.php index 7303809..531e027 100644 --- a/WebServiceContext.php +++ b/WebServiceContext.php @@ -76,7 +76,7 @@ class WebServiceContext $cache = new ConfigCache($file, $this->options['debug']); if(!$cache->isFresh()) { - $cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint))); + $cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), $endpoint)); } return (string) $cache;