[SoapBundle] Updated ComplexType strategy

This commit is contained in:
Francis Besset 2013-07-22 15:51:45 +02:00
parent be1e80799c
commit 04a94bbbe4
2 changed files with 48 additions and 22 deletions

View File

@ -128,9 +128,20 @@ 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()

View File

@ -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;
}
$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));
}
$dom = $this->getContext()->toDomDocument();
$soapTypeName = $this->getContext()->translateType($type);
$soapType = 'tns:'.$soapTypeName;
if (!$classmap->has($soapTypeName)) {
$classmap->add($soapTypeName, $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();
$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;
}
}