diff --git a/src/BeSimple/SoapBundle/ServiceDefinition/ServiceDefinition.php b/src/BeSimple/SoapBundle/ServiceDefinition/ServiceDefinition.php index 458f23d..b748c4b 100644 --- a/src/BeSimple/SoapBundle/ServiceDefinition/ServiceDefinition.php +++ b/src/BeSimple/SoapBundle/ServiceDefinition/ServiceDefinition.php @@ -128,13 +128,24 @@ class ServiceDefinition $this->classmap = $classmap; } + public function hasDefinitionComplexType($type) + { + return isset($this->complexTypes[$type]); + } + public function addDefinitionComplexType($type, Collection $complexType) { + if ($this->hasDefinitionComplexType($type)) { + return false; + } + $this->complexTypes[$type] = $complexType; + + return true; } public function getDefinitionComplexTypes() { return $this->complexTypes; } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapBundle/ServiceDefinition/Strategy/ComplexType.php b/src/BeSimple/SoapBundle/ServiceDefinition/Strategy/ComplexType.php index c8df45f..6be1228 100644 --- a/src/BeSimple/SoapBundle/ServiceDefinition/Strategy/ComplexType.php +++ b/src/BeSimple/SoapBundle/ServiceDefinition/Strategy/ComplexType.php @@ -38,40 +38,53 @@ class ComplexType extends AbstractComplexTypeStrategy */ public function addComplexType($type) { - $classmap = $this->definition->getClassmap(); - + // Really needed? if (null !== $soapType = $this->scanRegisteredTypes($type)) { return $soapType; } - if (!$this->loader->supports($type)) { - throw new \InvalidArgumentException(sprintf('Cannot add a complex type "%s" that is not an object or where class could not be found in "ComplexType" strategy.', $type)); + $classmap = $this->definition->getClassmap(); + if ($classmap->has($type)) { + $xmlName = $classmap->get($type); + $this->addDefinition($type, $xmlName); + + $xmlType = 'tns:'.$xmlName; + } else { + if (!$this->loader->supports($type)) { + throw new \InvalidArgumentException(sprintf('Cannot add a complex type "%s" that is not an object or where class could not be found in "ComplexType" strategy.', $type)); + } + + $xmlName = $this->getContext()->translateType($type); + $xmlType = 'tns:'.$xmlName; + + // Register type here to avoid recursion + $classmap->add($type, $xmlName); + $this->getContext()->addType($type, $soapType); + } + + $this->addDefinition($type, $xmlName); + + return $xmlType; + } + + private function addDefinition($type, $xmlName) + { + if ($this->definition->hasDefinitionComplexType($type)) { + return false; } $dom = $this->getContext()->toDomDocument(); - - $soapTypeName = $this->getContext()->translateType($type); - $soapType = 'tns:'.$soapTypeName; - - if (!$classmap->has($soapTypeName)) { - $classmap->add($soapTypeName, $type); - } - - // Register type here to avoid recursion - $this->getContext()->addType($type, $soapType); - $complexType = $dom->createElement('xsd:complexType'); - $complexType->setAttribute('name', $soapTypeName); + $complexType->setAttribute('name', $xmlName); $all = $dom->createElement('xsd:all'); + $elements = array(); $definitionComplexType = $this->loader->load($type); - $this->definition->addDefinitionComplexType($type, $definitionComplexType); - foreach ($definitionComplexType as $annotationComplexType) { $element = $dom->createElement('xsd:element'); - $element->setAttribute('name', $propertyName = $annotationComplexType->getName()); - $element->setAttribute('type', $this->getContext()->getType(trim($annotationComplexType->getValue()))); + $element->setAttribute('name', $annotationComplexType->getName()); + $element->setAttribute('type', $this->getContext()->getType($annotationComplexType->getValue())); if ($annotationComplexType->isNillable()) { $element->setAttribute('nillable', 'true'); @@ -83,6 +96,8 @@ class ComplexType extends AbstractComplexTypeStrategy $complexType->appendChild($all); $this->getContext()->getSchema()->appendChild($complexType); - return $soapType; + $this->definition->addDefinitionComplexType($type, $definitionComplexType); + + return true; } }