Fixed typo

This commit is contained in:
Francis Besset 2011-07-24 10:56:07 +02:00
parent 4fa893042f
commit ba0855a237
1 changed files with 40 additions and 40 deletions

View File

@ -16,71 +16,71 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType;
class RpcLiteralRequestMessageBinder implements MessageBinderInterface class RpcLiteralRequestMessageBinder implements MessageBinderInterface
{ {
private $definitionComplexTypes;
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
{ {
$this->definitionComplexTypes = $definitionComplexTypes;
$result = array(); $result = array();
$i = 0; $i = 0;
foreach($messageDefinition->getArguments() as $argument) { foreach($messageDefinition->getArguments() as $argument) {
if (isset($message[$i])) { if (isset($message[$i])) {
if (preg_match('/^([^\[]+)\[\]$/', $argument->getType()->getPhpType(), $match)) { $result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i]);
$isArray = true;
$type = $match[1];
} else {
$isArray = false;
$type = $argument->getType()->getPhpType();
}
if (isset($definitionComplexTypes[$type])) {
if ($isArray) {
$array = array();
foreach ($message[$i]->item as $complexType) {
$array[] = $this->getInstanceOfType($type, $complexType, $definitionComplexTypes);
}
$message[$i] = $array;
} else {
$message[$i] = $this->getInstanceOfType($type, $message[$i], $definitionComplexTypes);
}
} elseif ($isArray) {
$message[$i] = $message[$i]->item;
}
$result[$argument->getName()] = $message[$i];
} }
$i++; $i++;
} }
$this->definitionComplexTypes = array();
return $result; return $result;
} }
private function getInstanceOfType($type, $message, array $definitionComplexTypes) private function processType($phpType, $message)
{ {
$typeClass = $type; if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
$instanceType = new $typeClass(); $isArray = true;
$type = $match[1];
} else {
$isArray = false;
$type = $phpType;
}
foreach ($definitionComplexTypes[$type] as $type) { if (isset($this->definitionComplexTypes[$type])) {
if ($type instanceof PropertyComplexType) { if ($isArray) {
if (isset($definitionComplexTypes[$type->getValue()])) { $array = array();
$value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes);
} else { foreach ($message->item as $complexType) {
$value = $message->{$type->getName()}; $array[] = $this->getInstanceOfType($type, $complexType);
} }
$message = $array;
} else {
$message = $this->getInstanceOfType($type, $message);
}
} elseif ($isArray) {
$message = $message->item;
}
return $message;
}
private function getInstanceOfType($phpType, $message)
{
$instanceType = new $phpType();
foreach ($this->definitionComplexTypes[$phpType] as $type) {
$value = $this->processType($type->getValue(), $message->{$type->getName()});
if ($type instanceof PropertyComplexType) {
$instanceType->{$type->getOriginalName()} = $value; $instanceType->{$type->getOriginalName()} = $value;
} elseif ($type instanceof MethodComplexType) { } elseif ($type instanceof MethodComplexType) {
if (!$type->getSetter()) { if (!$type->getSetter()) {
throw new \LogicException(); throw new \LogicException();
} }
if (isset($definitionComplexTypes[$type->getValue()])) {
$value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes);
} else {
$value = $message->{$type->getName()};
}
$instanceType->{$type->getSetter()}($value); $instanceType->{$type->getSetter()}($value);
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();