[SoapBundle] Fixed ComplexType strategy to find Type by Classname

This commit is contained in:
Francis Besset 2013-07-22 20:34:25 +02:00
parent 16dddc0da6
commit 6de878de7d
2 changed files with 18 additions and 19 deletions

View File

@ -15,7 +15,7 @@
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter> <parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
<parameter key="besimple.soap.definition.dumper.wsdl.rpcliteral.class">BeSimple\SoapBundle\ServiceDefinition\Dumper\WsdlDumper</parameter> <parameter key="besimple.soap.definition.dumper.wsdl.rpcliteral.class">BeSimple\SoapBundle\ServiceDefinition\Dumper\WsdlDumper</parameter>
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapBundle\Converter\TypeRepository</parameter> <parameter key="besimple.soap.type.repository.class">BeSimple\SoapBundle\Converter\TypeRepository</parameter>
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapCommon\Classmap</parameter> <parameter key="besimple.soap.server.classmap.class">BeSimple\SoapServer\Classmap</parameter>
</parameters> </parameters>
<services> <services>

View File

@ -36,51 +36,50 @@ class ComplexType extends AbstractComplexTypeStrategy
* @param string $type Name of the class to be specified * @param string $type Name of the class to be specified
* @return string XSD Type for the given PHP type * @return string XSD Type for the given PHP type
*/ */
public function addComplexType($type) public function addComplexType($classname)
{ {
// Really needed? // Really needed?
if (null !== $soapType = $this->scanRegisteredTypes($type)) { if (null !== $type = $this->scanRegisteredTypes($classname)) {
return $soapType; return $type;
} }
$classmap = $this->definition->getClassmap(); $classmap = $this->definition->getClassmap();
if ($classmap->has($type)) { if ($classmap->hasByClassname($classname)) {
$xmlName = $classmap->get($type); $type = $classmap->getByClassname($classname);
$this->addDefinition($type, $xmlName);
$xmlType = 'tns:'.$xmlName; $xmlType = 'tns:'.$type;
} else { } else {
if (!$this->loader->supports($type)) { if (!$this->loader->supports($classname)) {
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)); 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.', $classname));
} }
$xmlName = $this->getContext()->translateType($type); $type = $this->getContext()->translateType($classname);
$xmlType = 'tns:'.$xmlName; $xmlType = 'tns:'.$type;
// Register type here to avoid recursion // Register type here to avoid recursion
$classmap->add($type, $xmlName); $classmap->add($type, $classname);
$this->getContext()->addType($type, $soapType); $this->getContext()->addType($classname, $xmlType);
} }
$this->addDefinition($type, $xmlName); $this->addXmlDefinition($classname, $type);
return $xmlType; return $xmlType;
} }
private function addDefinition($type, $xmlName) private function addXmlDefinition($classname, $type)
{ {
if ($this->definition->hasDefinitionComplexType($type)) { if ($this->definition->hasDefinitionComplexType($classname)) {
return false; return false;
} }
$dom = $this->getContext()->toDomDocument(); $dom = $this->getContext()->toDomDocument();
$complexType = $dom->createElement('xsd:complexType'); $complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $xmlName); $complexType->setAttribute('name', $type);
$all = $dom->createElement('xsd:all'); $all = $dom->createElement('xsd:all');
$elements = array(); $elements = array();
$definitionComplexType = $this->loader->load($type); $definitionComplexType = $this->loader->load($classname);
foreach ($definitionComplexType as $annotationComplexType) { foreach ($definitionComplexType as $annotationComplexType) {
$element = $dom->createElement('xsd:element'); $element = $dom->createElement('xsd:element');
$element->setAttribute('name', $annotationComplexType->getName()); $element->setAttribute('name', $annotationComplexType->getName());