diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 5929c9f..edef394 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -81,9 +81,11 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface { $hash = spl_object_hash($message); if (isset($this->messageRefs[$hash])) { - return $message; + return $this->messageRefs[$hash]; } + $this->messageRefs[$hash] = $message; + $r = new \ReflectionClass($message); foreach ($this->definitionComplexTypes[$phpType] as $type) { $p = $r->getProperty($type->getName()); @@ -101,6 +103,6 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface } } - return $this->messageRefs[$hash] = $message; + return $message; } } \ No newline at end of file diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index 4aab753..e021e94 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -130,6 +130,25 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => array()), $result); } + public function testProccessMessagePreventInfiniteRecursion() + { + $messageBinder = new RpcLiteralRequestMessageBinder(); + + $foo = new Fixtures\FooRecursive('foo', ''); + $bar = new Fixtures\BarRecursive($foo, 10394); + $foo->setBar($bar); + + $result = $messageBinder->processMessage( + new Definition\Method('prevent_infinite_recursion', null, array(), array( + new Definition\Argument('foo_recursive', new Definition\Type('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive')), + )), + array($foo), + $this->getDefinitionComplexTypes() + ); + + $this->assertEquals(array('foo_recursive' => $foo), $result); + } + public function messageProvider() { $messages = array(); @@ -198,6 +217,14 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'), )); + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'] = $this->createComplexTypeCollection(array( + array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'), + )); + + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive'] = $this->createComplexTypeCollection(array( + array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive'), + )); + return $definitionComplexTypes; }