From bacdc908703199ea89ef43070d4a1462534ab325 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sat, 26 Nov 2011 12:18:29 +0100 Subject: [PATCH] Moved Classmap instance in ServiceDefinition --- Resources/config/webservice.xml | 1 - ServiceDefinition/Dumper/WsdlDumper.php | 8 ++----- ServiceDefinition/Dumper/WsdlTypeStrategy.php | 8 ++----- ServiceDefinition/ServiceDefinition.php | 21 +++++++++++++++++-- ServiceDefinition/Strategy/ComplexType.php | 8 ++----- WebServiceContext.php | 5 ++++- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index abdf1a9..ae07e99 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -56,7 +56,6 @@ - %besimple.soap.definition.dumper.options.stylesheet% diff --git a/ServiceDefinition/Dumper/WsdlDumper.php b/ServiceDefinition/Dumper/WsdlDumper.php index 1d31687..5fbdf6f 100644 --- a/ServiceDefinition/Dumper/WsdlDumper.php +++ b/ServiceDefinition/Dumper/WsdlDumper.php @@ -18,25 +18,21 @@ use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; use BeSimple\SoapBundle\Util\Assert; use BeSimple\SoapBundle\Util\QName; -use BeSimple\SoapCommon\Classmap; - /** * @author Christian Kerl */ class WsdlDumper implements DumperInterface { private $loader; - private $classmap; private $typeRepository; private $options; private $wsdl; private $definition; - public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, TypeRepository $typeRepository, array $options) + public function __construct(AnnotationComplexTypeLoader $loader, TypeRepository $typeRepository, array $options) { $this->loader = $loader; - $this->classmap = $classmap; $this->typeRepository = $typeRepository; $this->options = $options; } @@ -46,7 +42,7 @@ class WsdlDumper implements DumperInterface Assert::thatArgumentNotNull('definition', $definition); $this->definition = $definition; - $this->wsdl = new Wsdl($this->typeRepository, $definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $this->classmap, $definition)); + $this->wsdl = new Wsdl($this->typeRepository, $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())); diff --git a/ServiceDefinition/Dumper/WsdlTypeStrategy.php b/ServiceDefinition/Dumper/WsdlTypeStrategy.php index 1d35d9c..62610e8 100644 --- a/ServiceDefinition/Dumper/WsdlTypeStrategy.php +++ b/ServiceDefinition/Dumper/WsdlTypeStrategy.php @@ -15,8 +15,6 @@ use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType; use BeSimple\SoapBundle\Util\String; -use BeSimple\SoapCommon\Classmap; - use Zend\Soap\Exception; use Zend\Soap\Wsdl as BaseWsdl; use Zend\Soap\Wsdl\Strategy; @@ -32,16 +30,14 @@ class WsdlTypeStrategy implements Strategy private $context; private $loader; - private $classmap; private $definition; private $typeStrategy; private $arrayStrategy; - public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, ServiceDefinition $definition) + public function __construct(AnnotationComplexTypeLoader $loader, ServiceDefinition $definition) { $this->loader = $loader; - $this->classmap = $classmap; $this->definition = $definition; } @@ -90,7 +86,7 @@ class WsdlTypeStrategy implements Strategy private function getTypeStrategy() { if (!$this->typeStrategy) { - $this->typeStrategy = new ComplexType($this->loader, $this->classmap, $this->definition); + $this->typeStrategy = new ComplexType($this->loader, $this->definition); $this->typeStrategy->setContext($this->context); } diff --git a/ServiceDefinition/ServiceDefinition.php b/ServiceDefinition/ServiceDefinition.php index adfd50b..458f23d 100644 --- a/ServiceDefinition/ServiceDefinition.php +++ b/ServiceDefinition/ServiceDefinition.php @@ -11,6 +11,7 @@ namespace BeSimple\SoapBundle\ServiceDefinition; use BeSimple\SoapBundle\Util\Collection; +use BeSimple\SoapCommon\Classmap; class ServiceDefinition { @@ -29,16 +30,22 @@ class ServiceDefinition */ private $methods; + /** + * @var \BeSimple\SoapCommon\Classmap + */ + private $classmap; + private $complexTypes = array(); - public function __construct($name = null, $namespace = null, array $methods = array()) + public function __construct($name = null, $namespace = null, array $methods = array(), Classmap $classmap = null) { $this->setName($name); $this->setNamespace($namespace); $this->methods = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Method'); - $this->setMethods($methods); + + $this->classmap = $classmap; } /** @@ -111,6 +118,16 @@ class ServiceDefinition return $types; } + public function getClassmap() + { + return $this->classmap ?: array(); + } + + public function setClassmap(Classmap $classmap) + { + $this->classmap = $classmap; + } + public function addDefinitionComplexType($type, Collection $complexType) { $this->complexTypes[$type] = $complexType; diff --git a/ServiceDefinition/Strategy/ComplexType.php b/ServiceDefinition/Strategy/ComplexType.php index b608902..696f425 100644 --- a/ServiceDefinition/Strategy/ComplexType.php +++ b/ServiceDefinition/Strategy/ComplexType.php @@ -11,8 +11,6 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Strategy; use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; - -use BeSimple\SoapCommon\Classmap; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\Strategy\AbstractStrategy; @@ -22,13 +20,11 @@ use Zend\Soap\Wsdl\Strategy\AbstractStrategy; class ComplexType extends AbstractStrategy { private $loader; - private $classmap; private $definition; - public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, $definition) + public function __construct(AnnotationComplexTypeLoader $loader, $definition) { $this->loader = $loader; - $this->classmap = $classmap; $this->definition = $definition; } @@ -53,7 +49,7 @@ class ComplexType extends AbstractStrategy $soapTypeName = Wsdl::translateType($type); $soapType = 'tns:'.$soapTypeName; - $this->classmap->add($soapTypeName, $type); + $this->definition->getClassmap()->add($soapTypeName, $type); // Register type here to avoid recursion $this->getContext()->addType($type, $soapType); diff --git a/WebServiceContext.php b/WebServiceContext.php index 556db5d..2cc879d 100644 --- a/WebServiceContext.php +++ b/WebServiceContext.php @@ -69,6 +69,9 @@ class WebServiceContext $this->serviceDefinition->setName($this->options['name']); $this->serviceDefinition->setNamespace($this->options['namespace']); + $this->serviceDefinition->setClassmap($this->classmap); + $this->classmap = null; + $this->typeRepository->fixTypeInformation($this->serviceDefinition); } } @@ -117,7 +120,7 @@ class WebServiceContext if (null === $this->serverBuilder) { $this->serverBuilder = SoapServerBuilder::createWithDefaults() ->withWsdl($this->getWsdlFile()) - ->withClassmap($this->classmap) + ->withClassmap($this->getServiceDefinition()->getClassmap()) ->withTypeConverters($this->converters) ;