diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index b97d503..37463de 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -20,6 +20,8 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; */ class RpcLiteralResponseMessageBinder implements MessageBinderInterface { + private $messageRefs = array(); + public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) { $return = $messageDefinition->getReturn(); @@ -61,7 +63,13 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface throw new \InvalidArgumentException(); } + $hash = spl_object_hash($message); + if (isset($this->messageRefs[$hash])) { + return $this->messageRefs[$hash]; + } + $stdClass = new \stdClass(); + $this->messageRefs[$hash] = $stdClass; foreach ($definitionComplexTypes[$type] as $type) { if ($type instanceof PropertyComplexType) { diff --git a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php index fe31332..2ccb4ea 100644 --- a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php @@ -83,6 +83,24 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame(123992, $result[1]->bar); } + public function testProcessMessageWithComplexTypeReferences() + { + $attributes = new Attributes(); + $attributes->foo = 'bar'; + $attributes->bar = 2929; + + $message = array($attributes, $attributes); + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_argument', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), + $message, + $this->getDefinitionComplexTypes() + ); + + $this->assertInstanceOf('stdClass', $result[0]); + $this->assertSame($result[0], $result[1]); + } + public function messageProvider() { $messages = array();