From ce5c46408a074e89bd4c768c0b240e2c51231f50 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Fri, 26 Aug 2011 23:39:43 +0200 Subject: [PATCH] Fixed issue #5 --- Controller/SoapWebServiceController.php | 4 +-- Converter/TypeRepository.php | 37 ++++++------------------- Resources/config/webservice.xml | 5 ++-- ServiceDefinition/Dumper/Wsdl.php | 22 +++++++++++++++ ServiceDefinition/Dumper/WsdlDumper.php | 11 +++++--- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Controller/SoapWebServiceController.php b/Controller/SoapWebServiceController.php index 4d6f315..250d99d 100644 --- a/Controller/SoapWebServiceController.php +++ b/Controller/SoapWebServiceController.php @@ -56,11 +56,9 @@ class SoapWebServiceController extends ContainerAware $webServiceContext = $this->getWebServiceContext($webservice); $this->serviceBinder = $webServiceContext->getServiceBinder(); - //$this->serviceBinder->fixXmlRequestContent(); $this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request')); - //$this->soapRequest->setContent($this->serviceBinder->fixXmlRequestContent($this->soapRequest->getContent())); - $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, $this->soapResponse); + $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, new SoapResponse()); $this->soapServer->setObject($this); diff --git a/Converter/TypeRepository.php b/Converter/TypeRepository.php index 2167a49..462dd75 100644 --- a/Converter/TypeRepository.php +++ b/Converter/TypeRepository.php @@ -40,7 +40,12 @@ class TypeRepository Assert::thatArgumentNotNull('phpType', $phpType); Assert::thatArgumentNotNull('xmlType', $xmlType); - $this->defaultTypeMap[$phpType] = $this->getQName($xmlType); + $this->defaultTypeMap[$phpType] = $xmlType; + } + + public function getXmlTypeMapping($phpType) + { + return isset($this->defaultTypeMap[$phpType]) ? $this->defaultTypeMap[$phpType] : null; } public function fixTypeInformation(ServiceDefinition $definition) @@ -56,36 +61,10 @@ class TypeRepository } if (null === $xmlType) { - if (!isset($typeMap[$phpType])) { - $parts = explode('\\', $phpType); - $xmlTypeName = ucfirst(end($parts)); - - if (String::endsWith($phpType, self::ARRAY_SUFFIX)) { - $xmlTypeName = str_replace(self::ARRAY_SUFFIX, 'Array', $xmlTypeName); - } - - $typeMap[$phpType] = new QName($definition->getNamespace(), $xmlTypeName); - } - - $xmlType = $typeMap[$phpType]; - } else { - $xmlType = $this->getQName($xmlType); + $xmlType = $this->getXmlTypeMapping($phpType); } - $type->setXmlType((string) $xmlType); + $type->setXmlType($xmlType); } } - - private function getQName($xmlType) - { - if (QName::isPrefixedQName($xmlType)) { - return QName::fromPrefixedQName($xmlType, array($this, 'getXmlNamespace')); - } else { - return QName::fromPackedQName($xmlType); - } - } - - public function createComplexTypeMap(ServiceDefinition $definition) - { - } } \ No newline at end of file diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index 80ebcb5..b1cd5f6 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -47,6 +47,7 @@ + %besimple.soap.definition.dumper.options.stylesheet% @@ -66,7 +67,7 @@ xsd:int - bool + boolean xsd:boolean @@ -74,7 +75,7 @@ xsd:float - DateTime + dateTime xsd:dateTime diff --git a/ServiceDefinition/Dumper/Wsdl.php b/ServiceDefinition/Dumper/Wsdl.php index 4410f9a..eeee674 100644 --- a/ServiceDefinition/Dumper/Wsdl.php +++ b/ServiceDefinition/Dumper/Wsdl.php @@ -10,6 +10,8 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Dumper; +use BeSimple\SoapBundle\Converter\TypeRepository; +use BeSimple\SoapBundle\ServiceDefinition\Type; use Zend\Soap\Wsdl as BaseWsdl; /** @@ -17,6 +19,26 @@ use Zend\Soap\Wsdl as BaseWsdl; */ class Wsdl extends BaseWsdl { + private $typeRepository; + + public function __construct(TypeRepository $typeRepository, $name, $uri, $strategy = true) + { + $this->typeRepository = $typeRepository; + + parent::__construct($name, $uri, $strategy); + } + + public function getType($type) + { + if ($type instanceof Type) { + $xmlType = $type->getXmlType(); + } else { + $xmlType = $this->typeRepository->getXmlTypeMapping($type); + } + + return $xmlType ?: $this->addComplexType($type); + } + public function addBindingOperationHeader(\DOMElement $bindingOperation, array $headers, array $baseBinding) { foreach ($headers as $header) { diff --git a/ServiceDefinition/Dumper/WsdlDumper.php b/ServiceDefinition/Dumper/WsdlDumper.php index 4979465..97517f7 100644 --- a/ServiceDefinition/Dumper/WsdlDumper.php +++ b/ServiceDefinition/Dumper/WsdlDumper.php @@ -10,6 +10,7 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Dumper; +use BeSimple\SoapBundle\Converter\TypeRepository; use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Type; use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition; @@ -23,15 +24,17 @@ use BeSimple\SoapBundle\Util\QName; class WsdlDumper implements DumperInterface { private $loader; + private $typeRepository; private $options; private $wsdl; private $definition; - public function __construct(AnnotationComplexTypeLoader $loader, array $options) + public function __construct(AnnotationComplexTypeLoader $loader, TypeRepository $typeRepository, array $options) { - $this->loader = $loader; - $this->options = $options; + $this->loader = $loader; + $this->typeRepository = $typeRepository; + $this->options = $options; } public function dumpServiceDefinition(ServiceDefinition $definition, $endpoint) @@ -39,7 +42,7 @@ class WsdlDumper implements DumperInterface Assert::thatArgumentNotNull('definition', $definition); $this->definition = $definition; - $this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $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()));