From 794d6cf8c2babee56a2343f9a411140d557d33d7 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 21 Feb 2013 08:22:55 +0100 Subject: [PATCH] Used MessageBinder of BeSimpleSoapCommon component --- .../doc/soapserver/tutorial/complex_type.rst | 52 +++++++++++++++++++ .../RpcLiteralRequestMessageBinder.php | 22 +++----- .../RpcLiteralResponseMessageBinder.php | 22 +++----- 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Resources/doc/soapserver/tutorial/complex_type.rst b/Resources/doc/soapserver/tutorial/complex_type.rst index f6ac0e3..034d762 100644 --- a/Resources/doc/soapserver/tutorial/complex_type.rst +++ b/Resources/doc/soapserver/tutorial/complex_type.rst @@ -43,6 +43,8 @@ User class You can expose only the properties (public, protected or private) of a complex type. +**For performance reasons, we advise to create getter and setter for each property.** + .. code-block:: php namespace Acme\DemoBundle\Entity; @@ -75,6 +77,56 @@ You can expose only the properties (public, protected or private) of a complex t * @Soap\ComplexType("string") */ private $email; + + /** + * @Soap\ComplexType("boolean") + */ + private $newsletter; + + public function getId() + { + return $this->id; + } + + public function getUsername() + { + return $this->username; + } + + public function getEmail() + { + return $this->email; + } + + public function getFirstname() + { + return $this->firstname; + } + + public function setFirstname($firstname) + { + $this->firstname = $firstname; + } + + public function getLastname() + { + return $this->lastname; + } + + public function setLastname($lastname) + { + $this->lastname = $lastname; + } + + public function hasNewsletter() + { + return $this->newsletter; + } + + public function setNewsletter($newsletter) + { + $this->newletter = (Boolean) $newsletter + } } ComplexType diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 917f50c..f3c0b99 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -1,8 +1,10 @@ + * (c) Francis Besset * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -13,8 +15,7 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; - -use Zend\Soap\Wsdl; +use BeSimple\SoapCommon\Util\MessageBinder; /** * @author Christian Kerl @@ -86,24 +87,15 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface $this->messageRefs[$hash] = $message; - $r = new \ReflectionClass($message); + $messageBinder = new MessageBinder($message); foreach ($this->definitionComplexTypes[$phpType] as $type) { - $p = $r->getProperty($type->getName()); - if ($p->isPublic()) { - $value = $message->{$type->getName()}; - } else { - $p->setAccessible(true); - $value = $p->getValue($message); - } + $property = $type->getName(); + $value = $messageBinder->readProperty($property); if (null !== $value) { $value = $this->processType($type->getValue(), $value); - if ($p->isPublic()) { - $message->{$type->getName()} = $value; - } else { - $p->setValue($message, $value); - } + $messageBinder->writeProperty($property, $value); } if (!$type->isNillable() && null === $value) { diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index cb6635b..bfb752d 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -1,8 +1,10 @@ + * (c) Francis Besset * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -13,8 +15,7 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; - -use Zend\Soap\Wsdl; +use BeSimple\SoapCommon\Util\MessageBinder; /** * @author Christian Kerl @@ -71,24 +72,15 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', get_class($message), $phpType)); } - $r = new \ReflectionClass($message); + $messageBinder = new MessageBinder($message); foreach ($this->definitionComplexTypes[$phpType] as $type) { - $p = $r->getProperty($type->getName()); - if ($p->isPublic()) { - $value = $message->{$type->getName()}; - } else { - $p->setAccessible(true); - $value = $p->getValue($message); - } + $property = $type->getName(); + $value = $messageBinder->readProperty($property); if (null !== $value) { $value = $this->processType($type->getValue(), $value); - if ($p->isPublic()) { - $message->{$type->getName()} = $value; - } else { - $p->setValue($message, $value); - } + $messageBinder->writeProperty($property, $value); } if (!$type->isNillable() && null === $value) {