Added recursion of types in RpcLiteralResponseMessageBinder
This commit is contained in:
parent
4e6592a38e
commit
966077aca0
|
@ -27,7 +27,7 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
||||||
$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])) {
|
||||||
$result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i], $definitionComplexTypes);
|
$result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i], $definitionComplexTypes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,58 +27,68 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface
|
||||||
$return = $messageDefinition->getReturn();
|
$return = $messageDefinition->getReturn();
|
||||||
$class = $return->getPhpType();
|
$class = $return->getPhpType();
|
||||||
|
|
||||||
if (preg_match('/^([^\[]+)\[\]$/', $class, $match)) {
|
$message = $this->processType($messageDefinition->getReturn()->getPhpType(), $message, $definitionComplexTypes);
|
||||||
|
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function processType($phpType, $message, array $definitionComplexTypes)
|
||||||
|
{
|
||||||
|
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
||||||
$isArray = true;
|
$isArray = true;
|
||||||
$type =
|
$type = $match[1];
|
||||||
$class = $match[1];
|
|
||||||
} else {
|
} else {
|
||||||
$isArray = false;
|
$isArray = false;
|
||||||
$type = $return->getPhpType();
|
$type = $phpType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($definitionComplexTypes[$type])) {
|
if (isset($definitionComplexTypes[$type])) {
|
||||||
if ($class[0] == '\\') {
|
|
||||||
$class = substr($class, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isArray) {
|
if ($isArray) {
|
||||||
$array = array();
|
$array = array();
|
||||||
|
|
||||||
foreach ($message as $complexType) {
|
foreach ($message as $complexType) {
|
||||||
$array[] = $this->getInstanceOfStdClass($type, $class, $complexType, $definitionComplexTypes);
|
$array[] = $this->getInstanceOfStdClass($type, $complexType, $definitionComplexTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = $array;
|
$message = $array;
|
||||||
} else {
|
} else {
|
||||||
$message = $this->getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes);
|
$message = $this->getInstanceOfStdClass($type, $message, $definitionComplexTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes)
|
private function getInstanceOfStdClass($phpType, $message, $definitionComplexTypes)
|
||||||
{
|
{
|
||||||
if (get_class($message) !== $class) {
|
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
$hash = spl_object_hash($message);
|
$hash = spl_object_hash($message);
|
||||||
if (isset($this->messageRefs[$hash])) {
|
if (isset($this->messageRefs[$hash])) {
|
||||||
return $this->messageRefs[$hash];
|
return $this->messageRefs[$hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$class = $phpType;
|
||||||
|
if ($class[0] == '\\') {
|
||||||
|
$class = substr($class, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_class($message) !== $class) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
$stdClass = new \stdClass();
|
$stdClass = new \stdClass();
|
||||||
$this->messageRefs[$hash] = $stdClass;
|
$this->messageRefs[$hash] = $stdClass;
|
||||||
|
|
||||||
foreach ($definitionComplexTypes[$type] as $type) {
|
foreach ($definitionComplexTypes[$phpType] as $type) {
|
||||||
|
|
||||||
if ($type instanceof PropertyComplexType) {
|
if ($type instanceof PropertyComplexType) {
|
||||||
$stdClass->{$type->getName()} = $message->{$type->getOriginalName()};
|
$value = $message->{$type->getOriginalName()};
|
||||||
} elseif ($type instanceof MethodComplexType) {
|
} elseif ($type instanceof MethodComplexType) {
|
||||||
$stdClass->{$type->getName()} = $message->{$type->getOriginalName()}();
|
$value = $message->{$type->getOriginalName()}();
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stdClass->{$type->getName()} = $this->processType($type->getValue(), $value, $definitionComplexTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $stdClass;
|
return $stdClass;
|
||||||
|
|
Loading…
Reference in New Issue