2010-10-08 14:24:42 +02:00
|
|
|
<?php
|
2013-02-21 08:22:55 +01:00
|
|
|
|
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>
|
2013-02-21 08:22:55 +01:00
|
|
|
* (c) Francis Besset <francis.besset@gmail.com>
|
2010-10-08 17:01:27 +02:00
|
|
|
*
|
|
|
|
* 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;
|
2013-02-21 08:22:55 +01:00
|
|
|
use BeSimple\SoapCommon\Util\MessageBinder;
|
2011-08-24 23:36:49 +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-08-24 23:36:49 +02:00
|
|
|
private $definitionComplexTypes;
|
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
|
|
|
{
|
2011-08-24 23:36:49 +02:00
|
|
|
$this->definitionComplexTypes = $definitionComplexTypes;
|
|
|
|
|
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-08-24 23:36:49 +02:00
|
|
|
$result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i]);
|
2011-07-24 10:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-08-24 23:36:49 +02:00
|
|
|
protected function processType($phpType, $message)
|
2011-07-24 10:56:07 +02:00
|
|
|
{
|
2011-08-24 23:36:49 +02:00
|
|
|
$isArray = false;
|
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
|
|
|
$isArray = true;
|
2011-09-01 20:18:28 +02:00
|
|
|
$array = array();
|
2011-08-24 23:36:49 +02:00
|
|
|
$phpType = $match[1];
|
2011-07-24 10:56:07 +02:00
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2011-08-24 23:36:49 +02:00
|
|
|
// @TODO Fix array reference
|
|
|
|
if (isset($this->definitionComplexTypes[$phpType])) {
|
2011-07-24 10:56:07 +02:00
|
|
|
if ($isArray) {
|
2011-09-01 20:18:28 +02:00
|
|
|
if (isset($message->item)) {
|
|
|
|
foreach ($message->item as $complexType) {
|
|
|
|
$array[] = $this->checkComplexType($phpType, $complexType);
|
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2011-07-24 10:56:07 +02:00
|
|
|
$message = $array;
|
|
|
|
} else {
|
2011-08-24 23:36:49 +02:00
|
|
|
$message = $this->checkComplexType($phpType, $message);
|
2011-07-17 10:46:54 +02:00
|
|
|
}
|
2011-07-24 10:56:07 +02:00
|
|
|
} elseif ($isArray) {
|
2011-09-01 20:18:28 +02:00
|
|
|
if (isset($message->item)) {
|
|
|
|
$message = $message->item;
|
|
|
|
} else {
|
|
|
|
$message = $array;
|
|
|
|
}
|
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-08-24 23:36:49 +02:00
|
|
|
protected function checkComplexType($phpType, $message)
|
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])) {
|
2011-09-08 21:25:45 +02:00
|
|
|
return $this->messageRefs[$hash];
|
2011-07-27 22:53:33 +02:00
|
|
|
}
|
|
|
|
|
2011-09-08 21:25:45 +02:00
|
|
|
$this->messageRefs[$hash] = $message;
|
|
|
|
|
2013-02-21 08:22:55 +01:00
|
|
|
$messageBinder = new MessageBinder($message);
|
2011-08-24 23:36:49 +02:00
|
|
|
foreach ($this->definitionComplexTypes[$phpType] as $type) {
|
2013-02-21 08:22:55 +01:00
|
|
|
$property = $type->getName();
|
|
|
|
$value = $messageBinder->readProperty($property);
|
2011-08-16 21:06:10 +02:00
|
|
|
|
2012-01-12 11:53:58 +01:00
|
|
|
if (null !== $value) {
|
2012-01-11 14:11:55 +01:00
|
|
|
$value = $this->processType($type->getValue(), $value);
|
2011-07-23 20:06:42 +02:00
|
|
|
|
2013-02-21 08:22:55 +01:00
|
|
|
$messageBinder->writeProperty($property, $value);
|
2012-01-12 11:45:15 +01:00
|
|
|
}
|
|
|
|
|
2011-08-24 23:36:49 +02:00
|
|
|
if (!$type->isNillable() && null === $value) {
|
2012-01-04 12:47:45 +01:00
|
|
|
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
|
2011-07-23 20:06:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 21:25:45 +02:00
|
|
|
return $message;
|
2011-07-23 20:06:42 +02:00
|
|
|
}
|
2012-01-12 11:53:58 +01:00
|
|
|
}
|