2010-10-08 14:24:42 +02:00
|
|
|
<?php
|
2010-10-08 17:01:27 +02:00
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2010-10-08 17:01:27 +02:00
|
|
|
*
|
|
|
|
* (c) Christian Kerl <christian-kerl@web.de>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\ServiceBinding;
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
2011-07-23 20:06:42 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType;
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-07-24 11:31:15 +02:00
|
|
|
/**
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
* @author Francis Besset <francis.besset@gmail.com>
|
|
|
|
*/
|
2010-10-08 14:24:42 +02:00
|
|
|
class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
|
|
|
{
|
2011-07-27 22:53:33 +02:00
|
|
|
private $messageRefs = array();
|
2011-07-24 10:56:07 +02:00
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
|
2010-10-08 14:24:42 +02:00
|
|
|
{
|
|
|
|
$result = array();
|
2011-07-17 10:46:54 +02:00
|
|
|
$i = 0;
|
2010-10-08 14:24:42 +02:00
|
|
|
|
2011-07-28 00:39:19 +02:00
|
|
|
foreach ($messageDefinition->getArguments() as $argument) {
|
2011-07-17 10:46:54 +02:00
|
|
|
if (isset($message[$i])) {
|
2011-07-27 22:53:33 +02:00
|
|
|
$result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i], $definitionComplexTypes);
|
2011-07-24 10:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-27 22:53:33 +02:00
|
|
|
private function processType($phpType, $message, array $definitionComplexTypes)
|
2011-07-24 10:56:07 +02:00
|
|
|
{
|
|
|
|
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
|
|
|
$isArray = true;
|
|
|
|
$type = $match[1];
|
|
|
|
} else {
|
|
|
|
$isArray = false;
|
|
|
|
$type = $phpType;
|
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-27 22:53:33 +02:00
|
|
|
if (isset($definitionComplexTypes[$type])) {
|
2011-07-24 10:56:07 +02:00
|
|
|
if ($isArray) {
|
|
|
|
$array = array();
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
foreach ($message->item as $complexType) {
|
2011-07-27 22:53:33 +02:00
|
|
|
$array[] = $this->getInstanceOfType($type, $complexType, $definitionComplexTypes);
|
2011-07-23 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
$message = $array;
|
|
|
|
} else {
|
2011-07-27 22:53:33 +02:00
|
|
|
$message = $this->getInstanceOfType($type, $message, $definitionComplexTypes);
|
2011-07-17 10:46:54 +02:00
|
|
|
}
|
2011-07-24 10:56:07 +02:00
|
|
|
} elseif ($isArray) {
|
|
|
|
$message = $message->item;
|
2010-10-08 14:24:42 +02:00
|
|
|
}
|
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
return $message;
|
2010-10-08 14:24:42 +02:00
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-27 22:53:33 +02:00
|
|
|
private function getInstanceOfType($phpType, $message, array $definitionComplexTypes)
|
2011-07-23 20:06:42 +02:00
|
|
|
{
|
2011-07-27 22:53:33 +02:00
|
|
|
$hash = spl_object_hash($message);
|
|
|
|
if (isset($this->messageRefs[$hash])) {
|
|
|
|
return $this->messageRefs[$hash];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->messageRefs[$hash] =
|
|
|
|
$instanceType = new $phpType();
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-27 22:53:33 +02:00
|
|
|
foreach ($definitionComplexTypes[$phpType] as $type) {
|
|
|
|
$value = $this->processType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes);
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
if ($type instanceof PropertyComplexType) {
|
2011-07-23 20:06:42 +02:00
|
|
|
$instanceType->{$type->getOriginalName()} = $value;
|
|
|
|
} elseif ($type instanceof MethodComplexType) {
|
|
|
|
if (!$type->getSetter()) {
|
|
|
|
throw new \LogicException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$instanceType->{$type->getSetter()}($value);
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instanceType;
|
|
|
|
}
|
2010-10-08 14:24:42 +02:00
|
|
|
}
|