[SoapBundle] Updated ComplexType strategy
This commit is contained in:
parent
be1e80799c
commit
04a94bbbe4
|
@ -128,9 +128,20 @@ class ServiceDefinition
|
||||||
$this->classmap = $classmap;
|
$this->classmap = $classmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasDefinitionComplexType($type)
|
||||||
|
{
|
||||||
|
return isset($this->complexTypes[$type]);
|
||||||
|
}
|
||||||
|
|
||||||
public function addDefinitionComplexType($type, Collection $complexType)
|
public function addDefinitionComplexType($type, Collection $complexType)
|
||||||
{
|
{
|
||||||
|
if ($this->hasDefinitionComplexType($type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$this->complexTypes[$type] = $complexType;
|
$this->complexTypes[$type] = $complexType;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefinitionComplexTypes()
|
public function getDefinitionComplexTypes()
|
||||||
|
|
|
@ -38,40 +38,53 @@ class ComplexType extends AbstractComplexTypeStrategy
|
||||||
*/
|
*/
|
||||||
public function addComplexType($type)
|
public function addComplexType($type)
|
||||||
{
|
{
|
||||||
$classmap = $this->definition->getClassmap();
|
// Really needed?
|
||||||
|
|
||||||
if (null !== $soapType = $this->scanRegisteredTypes($type)) {
|
if (null !== $soapType = $this->scanRegisteredTypes($type)) {
|
||||||
return $soapType;
|
return $soapType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->loader->supports($type)) {
|
$classmap = $this->definition->getClassmap();
|
||||||
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));
|
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();
|
$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 = $dom->createElement('xsd:complexType');
|
||||||
$complexType->setAttribute('name', $soapTypeName);
|
$complexType->setAttribute('name', $xmlName);
|
||||||
|
|
||||||
$all = $dom->createElement('xsd:all');
|
$all = $dom->createElement('xsd:all');
|
||||||
|
|
||||||
|
$elements = array();
|
||||||
$definitionComplexType = $this->loader->load($type);
|
$definitionComplexType = $this->loader->load($type);
|
||||||
$this->definition->addDefinitionComplexType($type, $definitionComplexType);
|
|
||||||
|
|
||||||
foreach ($definitionComplexType as $annotationComplexType) {
|
foreach ($definitionComplexType as $annotationComplexType) {
|
||||||
$element = $dom->createElement('xsd:element');
|
$element = $dom->createElement('xsd:element');
|
||||||
$element->setAttribute('name', $propertyName = $annotationComplexType->getName());
|
$element->setAttribute('name', $annotationComplexType->getName());
|
||||||
$element->setAttribute('type', $this->getContext()->getType(trim($annotationComplexType->getValue())));
|
$element->setAttribute('type', $this->getContext()->getType($annotationComplexType->getValue()));
|
||||||
|
|
||||||
if ($annotationComplexType->isNillable()) {
|
if ($annotationComplexType->isNillable()) {
|
||||||
$element->setAttribute('nillable', 'true');
|
$element->setAttribute('nillable', 'true');
|
||||||
|
@ -83,6 +96,8 @@ class ComplexType extends AbstractComplexTypeStrategy
|
||||||
$complexType->appendChild($all);
|
$complexType->appendChild($all);
|
||||||
$this->getContext()->getSchema()->appendChild($complexType);
|
$this->getContext()->getSchema()->appendChild($complexType);
|
||||||
|
|
||||||
return $soapType;
|
$this->definition->addDefinitionComplexType($type, $definitionComplexType);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue