From ade1584448625329c2fcdaca57d494010b1ec18f Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 8 Sep 2011 20:42:09 +0200 Subject: [PATCH 1/4] Fixed issue #8 --- ServiceBinding/RpcLiteralResponseMessageBinder.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index 2a9c8cb..a212ad9 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -79,12 +79,14 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface $p = $r->getProperty($type->getName()); if ($p->isPublic()) { $value = $message->{$type->getName()}; + + $message->{$type->getName()} = $this->processType($type->getValue(), $value); } else { $p->setAccessible(true); $value = $p->getValue($message); - } - $value = $this->processType($type->getValue(), $value); + $p->setValue($message, $this->processType($type->getValue(), $value)); + } if (!$type->isNillable() && null === $value) { throw new \InvalidArgumentException(sprintf('"%s::%s" cannot be null.', $class, $type->getName())); From 4850f782d5fd25657716bd5995dd119645aad352 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 8 Sep 2011 20:44:06 +0200 Subject: [PATCH 2/4] Updated RpcLiteralResponseMessageBinder to prevent infinite recursion --- ServiceBinding/RpcLiteralResponseMessageBinder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index a212ad9..ed3f2e4 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -65,6 +65,8 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface return $this->messageRefs[$hash]; } + $this->messageRefs[$hash] = $message; + $class = $phpType; if ($class[0] == '\\') { $class = substr($class, 1); @@ -93,6 +95,6 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface } } - return $this->messageRefs[$hash] = $message; + return $message; } } \ No newline at end of file From 08c51aebcf30b303bf979a420a4a6114198e8d57 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 8 Sep 2011 21:24:40 +0200 Subject: [PATCH 3/4] Fixed typo --- Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index dac112a..4aab753 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -188,12 +188,12 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase array('bar', 'int'), )); - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Bar'] = $this->createComplexTypeCollection(array( + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'] = $this->createComplexTypeCollection(array( array('foo', 'string'), array('bar', 'int', true), )); - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\FooBar'] = $this->createComplexTypeCollection(array( + $definitionComplexTypes['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar'] = $this->createComplexTypeCollection(array( array('foo', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo'), array('bar', 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar'), )); From 154863cc8451d37f5cec7e994238c66aa6d20d4a Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 8 Sep 2011 21:25:45 +0200 Subject: [PATCH 4/4] Prevent infinite recursion in RpcLiteralRequestMessageBinder --- .../RpcLiteralRequestMessageBinder.php | 6 +++-- .../RpcLiteralRequestMessageBinderTest.php | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) 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; }