From 4fa893042f4ac0b81e0b0be73f9619b6ef0c0461 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sat, 23 Jul 2011 20:06:42 +0200 Subject: [PATCH 01/16] New definition of complex type The exposure of complex type properties was done only with public property. Now you can expose properties and public methods. Before: In a complex type: /** * @var string */ public $var; After: In a complex type: use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; /** * @Soap\PropertyComplexType("string", name="var", nillable="true") */ public $username; private $email; /** * @Soap\MethodComplexType("string", name="email", nillable="true", setter="setEmail") */ public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; } name, nillable are optionnal. setter is optional and only available for MethodComplexType. --- Controller/SoapWebServiceController.php | 1 + Resources/config/loaders.xml | 5 + Resources/config/webservice.xml | 4 +- ServiceBinding/MessageBinderInterface.php | 2 +- .../RpcLiteralRequestMessageBinder.php | 62 +++++++++++- .../RpcLiteralResponseMessageBinder.php | 55 ++++++++++- ServiceBinding/ServiceBinder.php | 4 +- .../Annotation/MethodComplexType.php | 67 +++++++++++++ .../Annotation/PropertyComplexType.php | 56 +++++++++++ ServiceDefinition/Dumper/WsdlDumper.php | 9 +- ServiceDefinition/Dumper/WsdlTypeStrategy.php | 40 ++++++-- .../Loader/AnnotationClassLoader.php | 4 - .../Loader/AnnotationComplexTypeLoader.php | 94 +++++++++++++++++++ ServiceDefinition/ServiceDefinition.php | 12 +++ .../Strategy/BaseComplexType.php | 62 ++++++++++++ ServiceDefinition/Strategy/ComplexType.php | 81 ++++++++++++++++ .../Strategy/MethodComplexType.php | 29 ++++++ .../Strategy/PropertyComplexType.php | 18 ++++ WebServiceContext.php | 10 +- 19 files changed, 592 insertions(+), 23 deletions(-) create mode 100644 ServiceDefinition/Annotation/MethodComplexType.php create mode 100644 ServiceDefinition/Annotation/PropertyComplexType.php create mode 100644 ServiceDefinition/Loader/AnnotationComplexTypeLoader.php create mode 100644 ServiceDefinition/Strategy/BaseComplexType.php create mode 100644 ServiceDefinition/Strategy/ComplexType.php create mode 100644 ServiceDefinition/Strategy/MethodComplexType.php create mode 100644 ServiceDefinition/Strategy/PropertyComplexType.php diff --git a/Controller/SoapWebServiceController.php b/Controller/SoapWebServiceController.php index 90eede1..1816377 100644 --- a/Controller/SoapWebServiceController.php +++ b/Controller/SoapWebServiceController.php @@ -53,6 +53,7 @@ class SoapWebServiceController extends ContainerAware $this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request')); $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, $this->soapResponse); + $this->soapServer->setObject($this); ob_start(); diff --git a/Resources/config/loaders.xml b/Resources/config/loaders.xml index 51c4e10..4347f94 100644 --- a/Resources/config/loaders.xml +++ b/Resources/config/loaders.xml @@ -10,6 +10,7 @@ BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationDirectoryLoader BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationFileLoader BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationClassLoader + BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader @@ -29,6 +30,10 @@ + + + + diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index 5dc9f8f..3fb9b7e 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -50,7 +50,9 @@ - + + + diff --git a/ServiceBinding/MessageBinderInterface.php b/ServiceBinding/MessageBinderInterface.php index f355f76..542112b 100644 --- a/ServiceBinding/MessageBinderInterface.php +++ b/ServiceBinding/MessageBinderInterface.php @@ -20,5 +20,5 @@ interface MessageBinderInterface * * @return mixed */ - function processMessage(Method $messageDefinition, $message); + function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()); } \ No newline at end of file diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 12c8e78..c349b73 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -11,16 +11,42 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; class RpcLiteralRequestMessageBinder implements MessageBinderInterface { - public function processMessage(Method $messageDefinition, $message) + public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) { $result = array(); $i = 0; foreach($messageDefinition->getArguments() as $argument) { if (isset($message[$i])) { + if (preg_match('/^([^\[]+)\[\]$/', $argument->getType()->getPhpType(), $match)) { + $isArray = true; + $type = $match[1]; + } else { + $isArray = false; + $type = $argument->getType()->getPhpType(); + } + + if (isset($definitionComplexTypes[$type])) { + if ($isArray) { + $array = array(); + + foreach ($message[$i]->item as $complexType) { + $array[] = $this->getInstanceOfType($type, $complexType, $definitionComplexTypes); + } + + $message[$i] = $array; + } else { + $message[$i] = $this->getInstanceOfType($type, $message[$i], $definitionComplexTypes); + } + } elseif ($isArray) { + $message[$i] = $message[$i]->item; + } + $result[$argument->getName()] = $message[$i]; } @@ -29,4 +55,38 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface return $result; } + + private function getInstanceOfType($type, $message, array $definitionComplexTypes) + { + $typeClass = $type; + $instanceType = new $typeClass(); + + foreach ($definitionComplexTypes[$type] as $type) { + if ($type instanceof PropertyComplexType) { + if (isset($definitionComplexTypes[$type->getValue()])) { + $value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes); + } else { + $value = $message->{$type->getName()}; + } + + $instanceType->{$type->getOriginalName()} = $value; + } elseif ($type instanceof MethodComplexType) { + if (!$type->getSetter()) { + throw new \LogicException(); + } + + if (isset($definitionComplexTypes[$type->getValue()])) { + $value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes); + } else { + $value = $message->{$type->getName()}; + } + + $instanceType->{$type->getSetter()}($value); + } else { + throw new \InvalidArgumentException(); + } + } + + return $instanceType; + } } \ No newline at end of file diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index e4b4aa2..29b7d0e 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -11,11 +11,64 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; class RpcLiteralResponseMessageBinder implements MessageBinderInterface { - public function processMessage(Method $messageDefinition, $message) + public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) { + $return = $messageDefinition->getReturn(); + $class = $return->getPhpType(); + + if (preg_match('/^([^\[]+)\[\]$/', $class, $match)) { + $isArray = true; + $type = + $class = $match[1]; + } else { + $isArray = false; + $type = $return->getPhpType(); + } + + if (isset($definitionComplexTypes[$type])) { + if ($class[0] == '\\') { + $class = substr($class, 1); + } + + if ($isArray) { + $array = array(); + + foreach ($message as $complexType) { + $array[] = $this->getInstanceOfStdClass($type, $class, $complexType, $definitionComplexTypes); + } + + $message = $array; + } else { + $message = $this->getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes); + } + } + return $message; } + + private function getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes) + { + if (get_class($message) !== $class) { + throw new \InvalidArgumentException(); + } + + $stdClass = new \stdClass(); + + foreach ($definitionComplexTypes[$type] as $type) { + if ($type instanceof PropertyComplexType) { + $stdClass->{$type->getName()} = $message->{$type->getOriginalName()}; + } elseif ($type instanceof MethodComplexType) { + $stdClass->{$type->getName()} = $message->{$type->getOriginalName()}(); + } else { + throw new \InvalidArgumentException(); + } + } + + return $stdClass; + } } \ No newline at end of file diff --git a/ServiceBinding/ServiceBinder.php b/ServiceBinding/ServiceBinder.php index aa329f1..d6d46bc 100644 --- a/ServiceBinding/ServiceBinder.php +++ b/ServiceBinding/ServiceBinder.php @@ -61,7 +61,7 @@ class ServiceBinder $result = array(); $result['_controller'] = $methodDefinition->getController(); - $result = array_merge($result, $this->requestMessageBinder->processMessage($methodDefinition, $arguments)); + $result = array_merge($result, $this->requestMessageBinder->processMessage($methodDefinition, $arguments, $this->definition->getDefinitionComplexTypes())); return $result; } @@ -70,7 +70,7 @@ class ServiceBinder { $methodDefinition = $this->definition->getMethods()->get($name); - return $this->responseMessageBinder->processMessage($methodDefinition, $return); + return $this->responseMessageBinder->processMessage($methodDefinition, $return, $this->definition->getDefinitionComplexTypes()); } protected function createSoapHeader(Header $headerDefinition, $data) diff --git a/ServiceDefinition/Annotation/MethodComplexType.php b/ServiceDefinition/Annotation/MethodComplexType.php new file mode 100644 index 0000000..cf1cdaf --- /dev/null +++ b/ServiceDefinition/Annotation/MethodComplexType.php @@ -0,0 +1,67 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Annotation; + +/** + * @Annotation + */ +class MethodComplexType extends Configuration +{ + private $name; + private $value; + private $setter; + private $isNillable = false; + + public function getName() + { + return $this->name; + } + + public function getValue() + { + return $this->value; + } + + public function getSetter() + { + return $this->setter; + } + + public function isNillable() + { + return $this->isNillable; + } + + public function setName($name) + { + $this->name = $name; + } + + public function setValue($value) + { + $this->value = $value; + } + + public function setSetter($setter) + { + $this->setter = $setter; + } + + public function setNillable($isNillable) + { + $this->isNillable = (bool) $isNillable; + } + + public function getAliasName() + { + return 'methodcomplextype'; + } +} \ No newline at end of file diff --git a/ServiceDefinition/Annotation/PropertyComplexType.php b/ServiceDefinition/Annotation/PropertyComplexType.php new file mode 100644 index 0000000..6f1f046 --- /dev/null +++ b/ServiceDefinition/Annotation/PropertyComplexType.php @@ -0,0 +1,56 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Annotation; + +/** + * @Annotation + */ +class PropertyComplexType extends Configuration +{ + private $name; + private $value; + private $isNillable = false; + + public function getName() + { + return $this->name; + } + + public function getValue() + { + return $this->value; + } + + public function isNillable() + { + return $this->isNillable; + } + + public function setName($name) + { + $this->name = $name; + } + + public function setValue($value) + { + $this->value = $value; + } + + public function setNillable($isNillable) + { + $this->isNillable = (bool) $isNillable; + } + + public function getAliasName() + { + return 'propertycomplextype'; + } +} \ No newline at end of file diff --git a/ServiceDefinition/Dumper/WsdlDumper.php b/ServiceDefinition/Dumper/WsdlDumper.php index 09548b5..7c07064 100644 --- a/ServiceDefinition/Dumper/WsdlDumper.php +++ b/ServiceDefinition/Dumper/WsdlDumper.php @@ -13,6 +13,7 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Dumper; use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Type; use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition; +use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; use BeSimple\SoapBundle\Util\Assert; use BeSimple\SoapBundle\Util\QName; @@ -23,9 +24,15 @@ use Zend\Soap\Wsdl; */ class WsdlDumper implements DumperInterface { + private $loader; private $wsdl; private $definition; + public function __construct(AnnotationComplexTypeLoader $loader) + { + $this->loader = $loader; + } + public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()) { Assert::thatArgumentNotNull('definition', $definition); @@ -33,7 +40,7 @@ class WsdlDumper implements DumperInterface $options = array_merge(array('endpoint' => '', 'stylesheet' => null), $options); $this->definition = $definition; - $this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy()); + $this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition)); $port = $this->wsdl->addPortType($this->getPortTypeName()); $binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName())); diff --git a/ServiceDefinition/Dumper/WsdlTypeStrategy.php b/ServiceDefinition/Dumper/WsdlTypeStrategy.php index 8ca9acb..77aa131 100644 --- a/ServiceDefinition/Dumper/WsdlTypeStrategy.php +++ b/ServiceDefinition/Dumper/WsdlTypeStrategy.php @@ -10,13 +10,15 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Dumper; +use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition; +use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType; use BeSimple\SoapBundle\Util\String; use Zend\Soap\Exception; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\Strategy; use Zend\Soap\Wsdl\Strategy\ArrayOfTypeSequence; -use Zend\Soap\Wsdl\Strategy\DefaultComplexType; class WsdlTypeStrategy implements Strategy { @@ -27,13 +29,16 @@ class WsdlTypeStrategy implements Strategy */ private $context; + private $loader; + private $definition; + private $typeStrategy; private $arrayStrategy; - public function __construct() + public function __construct(AnnotationComplexTypeLoader $loader, ServiceDefinition $definition) { - $this->typeStrategy = new DefaultComplexType(); - $this->arrayStrategy = new ArrayOfTypeSequence(); + $this->loader = $loader; + $this->definition = $definition; } /** @@ -51,9 +56,11 @@ class WsdlTypeStrategy implements Strategy /** * Create a complex type based on a strategy * - * @throws \Zend\Soap\WsdlException * @param string $type + * * @return string XSD type + * + * @throws \Zend\Soap\WsdlException */ public function addComplexType($type) { @@ -61,9 +68,28 @@ class WsdlTypeStrategy implements Strategy throw new \LogicException(sprintf('Cannot add complex type "%s", no context is set for this composite strategy.', $type)); } - $strategy = String::endsWith($type, '[]') ? $this->arrayStrategy : $this->typeStrategy; - $strategy->setContext($this->context); + $strategy = String::endsWith($type, '[]') ? $this->getArrayStrategy() : $this->getTypeStrategy(); return $strategy->addComplexType($type); } + + private function getArrayStrategy() + { + if (!$this->arrayStrategy) { + $this->arrayStrategy = new ArrayOfTypeSequence(); + $this->arrayStrategy->setContext($this->context); + } + + return $this->arrayStrategy; + } + + private function getTypeStrategy() + { + if (!$this->typeStrategy) { + $this->typeStrategy = new ComplexType($this->loader, $this->definition); + $this->typeStrategy->setContext($this->context); + } + + return $this->typeStrategy; + } } \ No newline at end of file diff --git a/ServiceDefinition/Loader/AnnotationClassLoader.php b/ServiceDefinition/Loader/AnnotationClassLoader.php index 2faccbc..b71732f 100644 --- a/ServiceDefinition/Loader/AnnotationClassLoader.php +++ b/ServiceDefinition/Loader/AnnotationClassLoader.php @@ -32,10 +32,6 @@ use Symfony\Component\Config\Loader\LoaderResolver; */ class AnnotationClassLoader implements LoaderInterface { - private $methodAnnotationClass = 'BeSimple\\SoapBundle\\ServiceDefinition\\Annotation\\Method'; - private $paramAnnotationClass = 'BeSimple\\SoapBundle\\ServiceDefinition\\Annotation\\Param'; - private $resultAnnotationClass = 'BeSimple\\SoapBundle\\ServiceDefinition\\Annotation\\Result'; - protected $reader; /** diff --git a/ServiceDefinition/Loader/AnnotationComplexTypeLoader.php b/ServiceDefinition/Loader/AnnotationComplexTypeLoader.php new file mode 100644 index 0000000..21c9085 --- /dev/null +++ b/ServiceDefinition/Loader/AnnotationComplexTypeLoader.php @@ -0,0 +1,94 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Loader; + +use BeSimple\SoapBundle\ServiceDefinition\Annotation\ComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; +use BeSimple\SoapBundle\Util\Collection; + +/** + * AnnotationComplexTypeLoader loads ServiceDefinition from a PHP class and its methods. + * + * Based on \Symfony\Component\Routing\Loader\AnnotationClassLoader + * + * @author Francis Besset + */ +class AnnotationComplexTypeLoader extends AnnotationClassLoader +{ + private $propertyComplexTypeClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\PropertyComplexType'; + private $methodComplexTypeClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\MethodComplexType'; + + /** + * Loads a ServiceDefinition from annotations from a class. + * + * @param string $class A class name + * @param string $type The resource type + * + * @return ServiceDefinition A ServiceDefinition instance + * + * @throws \InvalidArgumentException When route can't be parsed + */ + public function load($class, $type = null) + { + if (!class_exists($class)) { + throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); + } + + $class = new \ReflectionClass($class); + $collection = new Collection('getName'); + + foreach ($class->getProperties() as $property) { + if ($property->isPublic()) { + $complexType = $this->reader->getPropertyAnnotation($property, $this->propertyComplexTypeClass); + + if ($complexType) { + $propertyComplexType = new PropertyComplexType(); + $propertyComplexType->setValue($complexType->getValue()); + $propertyComplexType->setNillable($complexType->isNillable()); + + if (!$complexType->getName()) { + $propertyComplexType->setName($property->getName()); + } else { + $propertyComplexType->setName($complexType->getName()); + $propertyComplexType->setOriginalName($property->getName()); + } + + $collection->add($propertyComplexType); + } + } + } + + foreach ($class->getMethods() as $method) { + if ($method->isPublic()) { + $complexType = $this->reader->getMethodAnnotation($method, $this->methodComplexTypeClass); + + if ($complexType) { + $methodComplexType = new MethodComplexType(); + $methodComplexType->setValue($complexType->getValue()); + $methodComplexType->setSetter($complexType->getSetter()); + $methodComplexType->setNillable($complexType->isNillable()); + + if (!$complexType->getName()) { + $methodComplexType->setName($property->getName()); + } else { + $methodComplexType->setName($complexType->getName()); + $methodComplexType->setOriginalName($method->getName()); + } + + $collection->add($methodComplexType); + } + } + } + + return $collection; + } +} \ No newline at end of file diff --git a/ServiceDefinition/ServiceDefinition.php b/ServiceDefinition/ServiceDefinition.php index d11e285..683de74 100644 --- a/ServiceDefinition/ServiceDefinition.php +++ b/ServiceDefinition/ServiceDefinition.php @@ -34,6 +34,8 @@ class ServiceDefinition */ private $headers; + private $complexTypes = array(); + public function __construct($name = null, $namespace = null, array $methods = array(), array $headers = array()) { $this->setName($name); @@ -127,4 +129,14 @@ class ServiceDefinition return $types; } + + public function addDefinitionComplexType($type, Collection $complexType) + { + $this->complexTypes[$type] = $complexType; + } + + public function getDefinitionComplexTypes() + { + return $this->complexTypes; + } } \ No newline at end of file diff --git a/ServiceDefinition/Strategy/BaseComplexType.php b/ServiceDefinition/Strategy/BaseComplexType.php new file mode 100644 index 0000000..917fb57 --- /dev/null +++ b/ServiceDefinition/Strategy/BaseComplexType.php @@ -0,0 +1,62 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Strategy; + +/** + * @author Francis Besset + */ +abstract class BaseComplexType +{ + private $name; + private $originalName; + private $value; + private $isNillable = false; + + public function getName() + { + return $this->name; + } + + public function getOriginalName() + { + return $this->originalName ?: $this->name; + } + + public function getValue() + { + return $this->value; + } + + public function isNillable() + { + return $this->isNillable; + } + + public function setName($name) + { + $this->name = $name; + } + + public function setOriginalName($originalName) + { + $this->originalName = $originalName; + } + + public function setValue($value) + { + $this->value = $value; + } + + public function setNillable($isNillable) + { + $this->isNillable = (bool) $isNillable; + } +} \ No newline at end of file diff --git a/ServiceDefinition/Strategy/ComplexType.php b/ServiceDefinition/Strategy/ComplexType.php new file mode 100644 index 0000000..8af3fb1 --- /dev/null +++ b/ServiceDefinition/Strategy/ComplexType.php @@ -0,0 +1,81 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Strategy; + +use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader; + +use Zend\Soap\Wsdl; +use Zend\Soap\Wsdl\Strategy\AbstractStrategy; + +/** + * @author Francis Besset + */ +class ComplexType extends AbstractStrategy +{ + private $loader; + private $definition; + + public function __construct(AnnotationComplexTypeLoader $loader, $definition) + { + $this->loader = $loader; + $this->definition = $definition; + } + + /** + * Add a complex type by recursivly using all the class properties fetched via Reflection. + * + * @param string $type Name of the class to be specified + * @return string XSD Type for the given PHP type + */ + public function addComplexType($type) + { + if (null !== $soapType = $this->scanRegisteredTypes($type)) { + return $soapType; + } + + if (!$this->loader->supports($type)) { + throw new \InvalidArgumentException(sprintf('Cannot add a complex type "%s" that is not an object or where class could not be found in "ComplexType" strategy.', $type)); + } + + $dom = $this->getContext()->toDomDocument(); + + $soapTypeName = Wsdl::translateType($type); + $soapType = 'tns:'.$soapTypeName; + + // Register type here to avoid recursion + $this->getContext()->addType($type, $soapType); + + $complexType = $dom->createElement('xsd:complexType'); + $complexType->setAttribute('name', $soapTypeName); + + $all = $dom->createElement('xsd:all'); + + $definitionComplexType = $this->loader->load($type); + $this->definition->addDefinitionComplexType($type, $definitionComplexType); + + foreach ($definitionComplexType as $annotationComplexType) { + $element = $dom->createElement('xsd:element'); + $element->setAttribute('name', $propertyName = $annotationComplexType->getName()); + $element->setAttribute('type', $this->getContext()->getType(trim($annotationComplexType->getValue()))); + + if ($annotationComplexType->isNillable()) { + $element->setAttribute('nillable', 'true'); + } + + $all->appendChild($element); + } + + $complexType->appendChild($all); + $this->getContext()->getSchema()->appendChild($complexType); + + return $soapType; + } +} \ No newline at end of file diff --git a/ServiceDefinition/Strategy/MethodComplexType.php b/ServiceDefinition/Strategy/MethodComplexType.php new file mode 100644 index 0000000..7205ab5 --- /dev/null +++ b/ServiceDefinition/Strategy/MethodComplexType.php @@ -0,0 +1,29 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Strategy; + +/** + * @author Francis Besset + */ +class MethodComplexType extends BaseComplexType +{ + private $setter; + + public function getSetter() + { + return $this->setter; + } + + public function setSetter($setter) + { + $this->setter = $setter; + } +} \ No newline at end of file diff --git a/ServiceDefinition/Strategy/PropertyComplexType.php b/ServiceDefinition/Strategy/PropertyComplexType.php new file mode 100644 index 0000000..7545f0e --- /dev/null +++ b/ServiceDefinition/Strategy/PropertyComplexType.php @@ -0,0 +1,18 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\ServiceDefinition\Strategy; + +/** + * @author Francis Besset + */ +class PropertyComplexType extends BaseComplexType +{ +} \ No newline at end of file diff --git a/WebServiceContext.php b/WebServiceContext.php index 0a429ee..f0acaf6 100644 --- a/WebServiceContext.php +++ b/WebServiceContext.php @@ -70,6 +70,11 @@ class WebServiceContext return $this->serviceDefinition; } + public function getWsdlFileContent($endpoint = null) + { + return file_get_contents($this->getWsdlFile($endpoint)); + } + public function getWsdlFile($endpoint = null) { $file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint)); @@ -82,11 +87,6 @@ class WebServiceContext return (string) $cache; } - public function getWsdlFileContent($endpoint = null) - { - return file_get_contents($this->getWsdlFile($endpoint)); - } - public function getServiceBinder() { if (null === $this->serviceBinder) { From ba0855a2379193309b5caa4a780e20d0c55b7ac4 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 24 Jul 2011 10:56:07 +0200 Subject: [PATCH 02/16] Fixed typo --- .../RpcLiteralRequestMessageBinder.php | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index c349b73..11d7430 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -16,71 +16,71 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; class RpcLiteralRequestMessageBinder implements MessageBinderInterface { + private $definitionComplexTypes; + public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) { + $this->definitionComplexTypes = $definitionComplexTypes; + $result = array(); $i = 0; foreach($messageDefinition->getArguments() as $argument) { if (isset($message[$i])) { - if (preg_match('/^([^\[]+)\[\]$/', $argument->getType()->getPhpType(), $match)) { - $isArray = true; - $type = $match[1]; - } else { - $isArray = false; - $type = $argument->getType()->getPhpType(); - } - - if (isset($definitionComplexTypes[$type])) { - if ($isArray) { - $array = array(); - - foreach ($message[$i]->item as $complexType) { - $array[] = $this->getInstanceOfType($type, $complexType, $definitionComplexTypes); - } - - $message[$i] = $array; - } else { - $message[$i] = $this->getInstanceOfType($type, $message[$i], $definitionComplexTypes); - } - } elseif ($isArray) { - $message[$i] = $message[$i]->item; - } - - $result[$argument->getName()] = $message[$i]; + $result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i]); } $i++; } + $this->definitionComplexTypes = array(); + return $result; } - private function getInstanceOfType($type, $message, array $definitionComplexTypes) + private function processType($phpType, $message) { - $typeClass = $type; - $instanceType = new $typeClass(); + if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) { + $isArray = true; + $type = $match[1]; + } else { + $isArray = false; + $type = $phpType; + } - foreach ($definitionComplexTypes[$type] as $type) { - if ($type instanceof PropertyComplexType) { - if (isset($definitionComplexTypes[$type->getValue()])) { - $value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes); - } else { - $value = $message->{$type->getName()}; + if (isset($this->definitionComplexTypes[$type])) { + if ($isArray) { + $array = array(); + + foreach ($message->item as $complexType) { + $array[] = $this->getInstanceOfType($type, $complexType); } + $message = $array; + } else { + $message = $this->getInstanceOfType($type, $message); + } + } elseif ($isArray) { + $message = $message->item; + } + + return $message; + } + + private function getInstanceOfType($phpType, $message) + { + $instanceType = new $phpType(); + + foreach ($this->definitionComplexTypes[$phpType] as $type) { + $value = $this->processType($type->getValue(), $message->{$type->getName()}); + + if ($type instanceof PropertyComplexType) { $instanceType->{$type->getOriginalName()} = $value; } elseif ($type instanceof MethodComplexType) { if (!$type->getSetter()) { throw new \LogicException(); } - if (isset($definitionComplexTypes[$type->getValue()])) { - $value = $this->getInstanceOfType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes); - } else { - $value = $message->{$type->getName()}; - } - $instanceType->{$type->getSetter()}($value); } else { throw new \InvalidArgumentException(); From fd7fcf215b9a72683f73faa9eff3a461ad8f0278 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 24 Jul 2011 11:31:15 +0200 Subject: [PATCH 03/16] Added authors --- ServiceBinding/DocumentLiteralWrappedRequestMessageBinder.php | 3 +++ .../DocumentLiteralWrappedResponseMessageBinder.php | 3 +++ ServiceBinding/MessageBinderInterface.php | 3 +++ ServiceBinding/RpcLiteralRequestMessageBinder.php | 4 ++++ ServiceBinding/RpcLiteralResponseMessageBinder.php | 4 ++++ ServiceBinding/ServiceBinder.php | 3 +++ 6 files changed, 20 insertions(+) diff --git a/ServiceBinding/DocumentLiteralWrappedRequestMessageBinder.php b/ServiceBinding/DocumentLiteralWrappedRequestMessageBinder.php index 3245448..5d779b0 100644 --- a/ServiceBinding/DocumentLiteralWrappedRequestMessageBinder.php +++ b/ServiceBinding/DocumentLiteralWrappedRequestMessageBinder.php @@ -12,6 +12,9 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; +/** + * @author Christian Kerl + */ class DocumentLiteralWrappedRequestMessageBinder implements MessageBinderInterface { public function processMessage(Method $messageDefinition, $message) diff --git a/ServiceBinding/DocumentLiteralWrappedResponseMessageBinder.php b/ServiceBinding/DocumentLiteralWrappedResponseMessageBinder.php index d8d7e78..21c72e0 100644 --- a/ServiceBinding/DocumentLiteralWrappedResponseMessageBinder.php +++ b/ServiceBinding/DocumentLiteralWrappedResponseMessageBinder.php @@ -12,6 +12,9 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; +/** + * @author Christian Kerl + */ class DocumentLiteralWrappedResponseMessageBinder implements MessageBinderInterface { public function processMessage(Method $messageDefinition, $message) diff --git a/ServiceBinding/MessageBinderInterface.php b/ServiceBinding/MessageBinderInterface.php index 542112b..85ca02f 100644 --- a/ServiceBinding/MessageBinderInterface.php +++ b/ServiceBinding/MessageBinderInterface.php @@ -12,6 +12,9 @@ namespace BeSimple\SoapBundle\ServiceBinding; use BeSimple\SoapBundle\ServiceDefinition\Method; +/** + * @author Christian Kerl + */ interface MessageBinderInterface { /** diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 11d7430..9fe758b 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -14,6 +14,10 @@ use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +/** + * @author Christian Kerl + * @author Francis Besset + */ class RpcLiteralRequestMessageBinder implements MessageBinderInterface { private $definitionComplexTypes; diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index 29b7d0e..b97d503 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -14,6 +14,10 @@ use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; +/** + * @author Christian Kerl + * @author Francis Besset + */ class RpcLiteralResponseMessageBinder implements MessageBinderInterface { public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) diff --git a/ServiceBinding/ServiceBinder.php b/ServiceBinding/ServiceBinder.php index d6d46bc..57065e6 100644 --- a/ServiceBinding/ServiceBinder.php +++ b/ServiceBinding/ServiceBinder.php @@ -15,6 +15,9 @@ use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition; use BeSimple\SoapBundle\Soap\SoapHeader; use BeSimple\SoapBundle\Util\QName; +/** + * @author Christian Kerl + */ class ServiceBinder { /** From 7d4e88c941c539fe586dd23aa918e545de0c7985 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 24 Jul 2011 14:40:52 +0200 Subject: [PATCH 04/16] Fixed typo in Util\Collection --- Util/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Util/Collection.php b/Util/Collection.php index e13703f..60b1256 100644 --- a/Util/Collection.php +++ b/Util/Collection.php @@ -25,7 +25,7 @@ class Collection implements \IteratorAggregate, \Countable public function add($element) { if ($this->class && !$element instanceof $this->class) { - throw new \InvalidArgument(sprintf('Cannot add class "%s" because it is not an instance of "%s"', get_class($element), $class)); + throw new \InvalidArgumentException(sprintf('Cannot add class "%s" because it is not an instance of "%s"', get_class($element), $this->class)); } $getter = $this->getter; From 444107b89aa755bc734e92504f5b744c324fcb96 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 24 Jul 2011 21:30:45 +0200 Subject: [PATCH 05/16] Added unit tests on RpcLiteralRequestMessageBinder --- .../RpcLiteralRequestMessageBinderTest.php | 136 ++++++++++++++++++ Tests/ServiceBinding/fixtures/Foo.php | 13 ++ 2 files changed, 149 insertions(+) create mode 100644 Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php create mode 100644 Tests/ServiceBinding/fixtures/Foo.php diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php new file mode 100644 index 0000000..6b6a90e --- /dev/null +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -0,0 +1,136 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\Tests\ServiceBinding; + +use BeSimple\SoapBundle\ServiceDefinition\Method; +use BeSimple\SoapBundle\ServiceDefinition\Argument; +use BeSimple\SoapBundle\ServiceDefinition\Type; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +use BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder; +use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo; +use BeSimple\SoapBundle\Util\Collection; + +/** + * UnitTest for \BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder. + * + * @author Francis Besset + */ +class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider messageProvider + */ + public function testProcessMessage(Method $method, $message, $assert) + { + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage($method, $message); + + $this->assertSame($assert, $result); + } + + /** + * @TODO test with complex type into complex type + * @TODO test setter and getter + */ + public function testProcessMessageWithComplexType() + { + $definitionComplexTypes = $this->getDefinitionComplexTypes(); + + $foo = new \stdClass(); + $foo->bar = 'foobar'; + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_argument', null, array( + new Argument('foo', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo')), + )), + array($foo), + $definitionComplexTypes + ); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo']); + $this->assertEquals('foobar', $result['foo']->bar); + + $foobar = new \stdClass(); + $foobar->bar = 'foobar'; + $barfoo = new \stdClass(); + $barfoo->bar = 'barfoo'; + $message = new \stdClass(); + $message->item = array($foobar, $barfoo); + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_argument', null, array( + new Argument('foo', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo[]')), + )), + array($message), + $definitionComplexTypes + ); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo'][0]); + $this->assertEquals('foobar', $result['foo'][0]->bar); + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo'][1]); + $this->assertEquals('barfoo', $result['foo'][1]->bar); + } + + public function messageProvider() + { + $messages = array(); + + $messages[] = array( + new Method('no_argument'), + array(), + array(), + ); + + $messages[] = array( + new Method('string_argument', null, array( + new Argument('foo', new Type('string')), + )), + array('bar'), + array('foo' => 'bar'), + ); + + $messages[] = array( + new Method('string_int_arguments', null, array( + new Argument('foo', new Type('string')), + new Argument('bar', new Type('int')), + )), + array('test', 20), + array('foo' => 'test', 'bar' => 20), + ); + + $strings = new \stdClass(); + $strings->item = array('foo', 'bar', 'barfoo'); + $messages[] = array( + new Method('array_string_arguments', null, array( + new Argument('foo', new Type('string[]')), + new Argument('bar', new Type('int')), + )), + array($strings, 4), + array('foo' => array('foo', 'bar', 'barfoo'), 'bar' => 4), + ); + + return $messages; + } + + public function getDefinitionComplexTypes() + { + $this->definitionComplexTypes = array(); + + $collection = new Collection('getName'); + $property = new PropertyComplexType(); + $property->setName('bar'); + $property->setValue('string'); + $collection->add($property); + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo'] = $collection; + + return $this->definitionComplexTypes; + } +} diff --git a/Tests/ServiceBinding/fixtures/Foo.php b/Tests/ServiceBinding/fixtures/Foo.php new file mode 100644 index 0000000..e3d570b --- /dev/null +++ b/Tests/ServiceBinding/fixtures/Foo.php @@ -0,0 +1,13 @@ +bar = $bar; + } +} \ No newline at end of file From 483e8d1bb24f1978e3a9c0c811e9c57931da8462 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 27 Jul 2011 00:13:24 +0200 Subject: [PATCH 06/16] Added tests on RpcLiteralRequestMessageBinder --- .../RpcLiteralRequestMessageBinderTest.php | 153 ++++++++++++++---- Tests/ServiceBinding/fixtures/Attributes.php | 9 ++ Tests/ServiceBinding/fixtures/ComplexType.php | 20 +++ Tests/ServiceBinding/fixtures/Foo.php | 13 -- Tests/ServiceBinding/fixtures/Setters.php | 29 ++++ 5 files changed, 183 insertions(+), 41 deletions(-) create mode 100644 Tests/ServiceBinding/fixtures/Attributes.php create mode 100644 Tests/ServiceBinding/fixtures/ComplexType.php delete mode 100644 Tests/ServiceBinding/fixtures/Foo.php create mode 100644 Tests/ServiceBinding/fixtures/Setters.php diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index 6b6a90e..3c8a380 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -14,8 +14,8 @@ use BeSimple\SoapBundle\ServiceDefinition\Method; use BeSimple\SoapBundle\ServiceDefinition\Argument; use BeSimple\SoapBundle\ServiceDefinition\Type; use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; use BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder; -use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo; use BeSimple\SoapBundle\Util\Collection; /** @@ -36,47 +36,101 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame($assert, $result); } - /** - * @TODO test with complex type into complex type - * @TODO test setter and getter - */ public function testProcessMessageWithComplexType() { $definitionComplexTypes = $this->getDefinitionComplexTypes(); - $foo = new \stdClass(); - $foo->bar = 'foobar'; + $attributes = new \stdClass(); + $attributes->foo = 'bar'; + $attributes->bar = 10; $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_argument', null, array( - new Argument('foo', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo')), + new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')), )), - array($foo), + array($attributes), $definitionComplexTypes ); - $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo']); - $this->assertEquals('foobar', $result['foo']->bar); + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['attributes']); + $this->assertSame('bar', $result['attributes']->foo); + $this->assertSame(10, $result['attributes']->bar); - $foobar = new \stdClass(); - $foobar->bar = 'foobar'; - $barfoo = new \stdClass(); - $barfoo->bar = 'barfoo'; + $attributes1 = new \stdClass(); + $attributes1->foo = 'foobar'; + $attributes1->bar = 11; + $attributes2 = new \stdClass(); + $attributes2->foo = 'barfoo'; + $attributes2->bar = 12; $message = new \stdClass(); - $message->item = array($foobar, $barfoo); + $message->item = array($attributes1, $attributes2); $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_argument', null, array( - new Argument('foo', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo[]')), + new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), )), array($message), $definitionComplexTypes ); - $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo'][0]); - $this->assertEquals('foobar', $result['foo'][0]->bar); - $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo', $result['foo'][1]); - $this->assertEquals('barfoo', $result['foo'][1]->bar); + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['attributes'][0]); + $this->assertSame('foobar', $result['attributes'][0]->foo); + $this->assertSame(11, $result['attributes'][0]->bar); + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['attributes'][1]); + $this->assertSame('barfoo', $result['attributes'][1]->foo); + $this->assertSame(12, $result['attributes'][1]->bar); + } + + public function testProcessMessageWithComplexTypeIntoComplexType() + { + $definitionComplexTypes = $this->getDefinitionComplexTypes(); + + $methods = new \stdClass(); + $methods->foo = 'bar'; + $methods->bar = 23; + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_methods', null, array( + new Argument('setters', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')), + )), + array($methods), + $definitionComplexTypes + ); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters', $result['setters']); + $this->assertSame('bar', $result['setters']->getFoo()); + $this->assertSame(23, $result['setters']->getBar()); + } + + public function testProcessMessageWithComplexTypeMethods() + { + $definitionComplexTypes = $this->getDefinitionComplexTypes(); + + $complexType = new \stdClass(); + $foo = $complexType->foo = new \stdClass(); + $foo->foo = 'hello'; + $foo->bar = 24; + $bar = $complexType->bar = new \stdClass(); + $bar->foo = 'bonjour'; + $bar->bar = 1012; + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_complextype', null, array( + new Argument('complex_type', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')), + )), + array($complexType), + $definitionComplexTypes + ); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType', $result['complex_type']); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['complex_type']->getFoo()); + $this->assertSame('hello', $result['complex_type']->getFoo()->foo); + $this->assertSame(24, $result['complex_type']->getFoo()->bar); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters', $result['complex_type']->bar); + $this->assertSame('bonjour', $result['complex_type']->bar->getFoo()); + $this->assertSame(1012, $result['complex_type']->bar->getBar()); } public function messageProvider() @@ -120,17 +174,60 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase return $messages; } - public function getDefinitionComplexTypes() + private function getDefinitionComplexTypes() { $this->definitionComplexTypes = array(); - $collection = new Collection('getName'); - $property = new PropertyComplexType(); - $property->setName('bar'); - $property->setValue('string'); - $collection->add($property); - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Foo'] = $collection; + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes'] = $this->createPropertiesCollection(array( + array('foo', 'string'), + array('bar', 'int'), + )); + + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'] = $this->createMethodsCollection(array( + array('foo', 'string', 'getFoo', 'setFoo'), + array('bar', 'int', 'getBar', 'setBar'), + )); + + $collection = $this->createMethodsCollection(array( + array('foo', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', 'getFoo', 'setFoo'), + )); + $this->createPropertiesCollection(array( + array('bar', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'), + ), $collection); + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType'] = $collection; return $this->definitionComplexTypes; } + + private function createPropertiesCollection(array $properties, Collection $collection = null) + { + $collection = $collection ?: new Collection('getName'); + + foreach ($properties as $property) { + $collectionProperty = new PropertyComplexType(); + $collectionProperty->setName($property[0]); + $collectionProperty->setValue($property[1]); + + $collection->add($collectionProperty); + } + + return $collection; + } + + private function createMethodsCollection(array $methods, Collection $collection = null) + { + $collection = $collection ?: new Collection('getName'); + + foreach ($methods as $method) { + $collectionMethod = new MethodComplexType(); + $collectionMethod->setName($method[0]); + $collectionMethod->setValue($method[1]); + $collectionMethod->setOriginalName($method[2]); + $collectionMethod->setSetter($method[3]); + + $collection->add($collectionMethod); + } + + return $collection; + } } diff --git a/Tests/ServiceBinding/fixtures/Attributes.php b/Tests/ServiceBinding/fixtures/Attributes.php new file mode 100644 index 0000000..53d4aee --- /dev/null +++ b/Tests/ServiceBinding/fixtures/Attributes.php @@ -0,0 +1,9 @@ +foo; + } + + public function setFoo($foo) + { + $this->foo = $foo; + } +} \ No newline at end of file diff --git a/Tests/ServiceBinding/fixtures/Foo.php b/Tests/ServiceBinding/fixtures/Foo.php deleted file mode 100644 index e3d570b..0000000 --- a/Tests/ServiceBinding/fixtures/Foo.php +++ /dev/null @@ -1,13 +0,0 @@ -bar = $bar; - } -} \ No newline at end of file diff --git a/Tests/ServiceBinding/fixtures/Setters.php b/Tests/ServiceBinding/fixtures/Setters.php new file mode 100644 index 0000000..a8de35a --- /dev/null +++ b/Tests/ServiceBinding/fixtures/Setters.php @@ -0,0 +1,29 @@ +foo; + } + + public function setFoo($foo) + { + $this->foo = $foo; + } + + public function getBar() + { + return $this->bar; + } + + public function setBar($bar) + { + $this->bar = $bar; + } +} \ No newline at end of file From 2994129b8d06491efe88f2cf1d7d4b4165892995 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 27 Jul 2011 00:48:45 +0200 Subject: [PATCH 07/16] Added RpcLiteralResponseMessageBinderTest --- .../RpcLiteralResponseMessageBinderTest.php | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php diff --git a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php new file mode 100644 index 0000000..fe31332 --- /dev/null +++ b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php @@ -0,0 +1,131 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\Tests\ServiceBinding; + +use BeSimple\SoapBundle\ServiceDefinition\Method; +use BeSimple\SoapBundle\ServiceDefinition\Type; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; +use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; +use BeSimple\SoapBundle\ServiceBinding\RpcLiteralResponseMessageBinder; +use BeSimple\SoapBundle\Util\Collection; +use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes; + +/** + * UnitTest for \BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder. + * + * @author Francis Besset + */ +class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider messageProvider + */ + public function testProcessMessage(Method $method, $message, $assert) + { + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage($method, $message); + + $this->assertSame($assert, $result); + } + + /** + * @TODO test with complex type into complex type + * @TODO test setter and getter + */ + public function testProcessMessageWithComplexType() + { + $definitionComplexTypes = $this->getDefinitionComplexTypes(); + + $attributes = new Attributes(); + $attributes->foo = 'foobar'; + $attributes->bar = 20349; + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')), + $attributes, + $definitionComplexTypes + ); + + $this->assertInstanceOf('stdClass', $result); + $this->assertSame('foobar', $result->foo); + $this->assertSame(20349, $result->bar); + + $attributes1 = new Attributes(); + $attributes1->foo = 'bar'; + $attributes1->bar = 2929; + $attributes2 = new Attributes(); + $attributes2->foo = 'foo'; + $attributes2->bar = 123992; + $message = array($attributes1, $attributes2); + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_argument', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), + $message, + $definitionComplexTypes + ); + + $this->assertTrue(is_array($result)); + + $this->assertInstanceOf('stdClass', $result[0]); + $this->assertSame('bar', $result[0]->foo); + $this->assertSame(2929, $result[0]->bar); + + $this->assertInstanceOf('stdClass', $result[1]); + $this->assertSame('foo', $result[1]->foo); + $this->assertSame(123992, $result[1]->bar); + } + + public function messageProvider() + { + $messages = array(); + + $messages[] = array( + new Method('boolean', null, array(), new Type('boolean')), + true, + true, + ); + + $messages[] = array( + new Method('strings', null, array(), new Type('string[]')), + array('hello', 'world'), + array('hello', 'world'), + ); + + return $messages; + } + + private function getDefinitionComplexTypes() + { + $this->definitionComplexTypes = array(); + + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes'] = $this->createPropertiesCollection(array( + array('foo', 'string'), + array('bar', 'int'), + )); + + return $this->definitionComplexTypes; + } + + private function createPropertiesCollection(array $properties, Collection $collection = null) + { + $collection = $collection ?: new Collection('getName'); + + foreach ($properties as $property) { + $collectionProperty = new PropertyComplexType(); + $collectionProperty->setName($property[0]); + $collectionProperty->setValue($property[1]); + + $collection->add($collectionProperty); + } + + return $collection; + } +} From 8cd07acc1183097196196ee048db68c0bc81b6ab Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 27 Jul 2011 22:53:33 +0200 Subject: [PATCH 08/16] Used the object hash in RpcLiteralRequestMessageBinder to return a same instance of an object --- .../RpcLiteralRequestMessageBinder.php | 30 ++++++----- .../RpcLiteralRequestMessageBinderTest.php | 54 +++++++++++++++---- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 9fe758b..310860f 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -20,29 +20,25 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; */ class RpcLiteralRequestMessageBinder implements MessageBinderInterface { - private $definitionComplexTypes; + private $messageRefs = array(); public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array()) { - $this->definitionComplexTypes = $definitionComplexTypes; - $result = array(); $i = 0; foreach($messageDefinition->getArguments() as $argument) { if (isset($message[$i])) { - $result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i]); + $result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i], $definitionComplexTypes); } $i++; } - $this->definitionComplexTypes = array(); - return $result; } - private function processType($phpType, $message) + private function processType($phpType, $message, array $definitionComplexTypes) { if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) { $isArray = true; @@ -52,17 +48,17 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface $type = $phpType; } - if (isset($this->definitionComplexTypes[$type])) { + if (isset($definitionComplexTypes[$type])) { if ($isArray) { $array = array(); foreach ($message->item as $complexType) { - $array[] = $this->getInstanceOfType($type, $complexType); + $array[] = $this->getInstanceOfType($type, $complexType, $definitionComplexTypes); } $message = $array; } else { - $message = $this->getInstanceOfType($type, $message); + $message = $this->getInstanceOfType($type, $message, $definitionComplexTypes); } } elseif ($isArray) { $message = $message->item; @@ -71,12 +67,18 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface return $message; } - private function getInstanceOfType($phpType, $message) + private function getInstanceOfType($phpType, $message, array $definitionComplexTypes) { - $instanceType = new $phpType(); + $hash = spl_object_hash($message); + if (isset($this->messageRefs[$hash])) { + return $this->messageRefs[$hash]; + } - foreach ($this->definitionComplexTypes[$phpType] as $type) { - $value = $this->processType($type->getValue(), $message->{$type->getName()}); + $this->messageRefs[$hash] = + $instanceType = new $phpType(); + + foreach ($definitionComplexTypes[$phpType] as $type) { + $value = $this->processType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes); if ($type instanceof PropertyComplexType) { $instanceType->{$type->getOriginalName()} = $value; diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index 3c8a380..a9b1ee0 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -38,18 +38,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase public function testProcessMessageWithComplexType() { - $definitionComplexTypes = $this->getDefinitionComplexTypes(); - $attributes = new \stdClass(); $attributes->foo = 'bar'; $attributes->bar = 10; + $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_argument', null, array( new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')), )), array($attributes), - $definitionComplexTypes + $this->getDefinitionComplexTypes() ); $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['attributes']); @@ -62,15 +61,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $attributes2 = new \stdClass(); $attributes2->foo = 'barfoo'; $attributes2->bar = 12; + $message = new \stdClass(); $message->item = array($attributes1, $attributes2); + $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_argument', null, array( new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), )), array($message), - $definitionComplexTypes + $this->getDefinitionComplexTypes() ); $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', $result['attributes'][0]); @@ -83,18 +84,17 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase public function testProcessMessageWithComplexTypeIntoComplexType() { - $definitionComplexTypes = $this->getDefinitionComplexTypes(); - $methods = new \stdClass(); $methods->foo = 'bar'; $methods->bar = 23; + $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_methods', null, array( new Argument('setters', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')), )), array($methods), - $definitionComplexTypes + $this->getDefinitionComplexTypes() ); $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters', $result['setters']); @@ -104,22 +104,22 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase public function testProcessMessageWithComplexTypeMethods() { - $definitionComplexTypes = $this->getDefinitionComplexTypes(); - $complexType = new \stdClass(); $foo = $complexType->foo = new \stdClass(); $foo->foo = 'hello'; $foo->bar = 24; + $bar = $complexType->bar = new \stdClass(); $bar->foo = 'bonjour'; $bar->bar = 1012; + $messageBinder = new RpcLiteralRequestMessageBinder(); $result = $messageBinder->processMessage( new Method('complextype_complextype', null, array( new Argument('complex_type', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')), )), array($complexType), - $definitionComplexTypes + $this->getDefinitionComplexTypes() ); $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType', $result['complex_type']); @@ -133,6 +133,40 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame(1012, $result['complex_type']->bar->getBar()); } + public function testProcessMessageWithComplexTypeReferences() + { + $complexType1 = new \stdClass(); + $foo = $complexType1->foo = new \stdClass(); + $foo->foo = 'hello'; + $foo->bar = 24; + + $bar = $complexType1->bar = new \stdClass(); + $bar->foo = 'bonjour'; + $bar->bar = 1012; + + $complexType2 = new \stdClass(); + $complexType2->foo = $foo; + $complexType2->bar = $bar; + + $complexTypes = new \stdClass(); + $complexTypes->item = array($complexType1, $complexType2); + + $messageBinder = new RpcLiteralRequestMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextypes_references', null, array( + new Argument('complex_types', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType[]')), + )), + array($complexTypes), + $this->getDefinitionComplexTypes() + ); + + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType', $result['complex_types'][0]); + $this->assertInstanceOf('BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType', $result['complex_types'][1]); + + $this->assertSame($result['complex_types'][0]->getFoo(), $result['complex_types'][1]->getFoo()); + $this->assertSame($result['complex_types'][0]->bar, $result['complex_types'][1]->bar); + } + public function messageProvider() { $messages = array(); From a0a321646963ff1d5763b45fb62e9d82daf44196 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 27 Jul 2011 23:15:47 +0200 Subject: [PATCH 09/16] Used the object hash in RpcLiteralResponseMessageBinder to return a same instance of an object --- .../RpcLiteralResponseMessageBinder.php | 8 ++++++++ .../RpcLiteralResponseMessageBinderTest.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) 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(); From 4e6592a38e2fe9de039b5e94d2bc3e91264dde5c Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 27 Jul 2011 23:38:21 +0200 Subject: [PATCH 10/16] 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 a9b1ee0..0eb1997 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -82,7 +82,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame(12, $result['attributes'][1]->bar); } - public function testProcessMessageWithComplexTypeIntoComplexType() + public function testProcessMessageWithComplexTypeMethods() { $methods = new \stdClass(); $methods->foo = 'bar'; @@ -102,7 +102,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame(23, $result['setters']->getBar()); } - public function testProcessMessageWithComplexTypeMethods() + public function testProcessMessageWithComplexTypeIntoComplexType() { $complexType = new \stdClass(); $foo = $complexType->foo = new \stdClass(); From 966077aca0327e67672f293a17044ed9cbbe1d06 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 28 Jul 2011 00:39:19 +0200 Subject: [PATCH 11/16] Added recursion of types in RpcLiteralResponseMessageBinder --- .../RpcLiteralRequestMessageBinder.php | 2 +- .../RpcLiteralResponseMessageBinder.php | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/ServiceBinding/RpcLiteralRequestMessageBinder.php b/ServiceBinding/RpcLiteralRequestMessageBinder.php index 310860f..2d3c32d 100644 --- a/ServiceBinding/RpcLiteralRequestMessageBinder.php +++ b/ServiceBinding/RpcLiteralRequestMessageBinder.php @@ -27,7 +27,7 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface $result = array(); $i = 0; - foreach($messageDefinition->getArguments() as $argument) { + foreach ($messageDefinition->getArguments() as $argument) { if (isset($message[$i])) { $result[$argument->getName()] = $this->processType($argument->getType()->getPhpType(), $message[$i], $definitionComplexTypes); } diff --git a/ServiceBinding/RpcLiteralResponseMessageBinder.php b/ServiceBinding/RpcLiteralResponseMessageBinder.php index 37463de..fcf5f77 100644 --- a/ServiceBinding/RpcLiteralResponseMessageBinder.php +++ b/ServiceBinding/RpcLiteralResponseMessageBinder.php @@ -27,58 +27,68 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface $return = $messageDefinition->getReturn(); $class = $return->getPhpType(); - if (preg_match('/^([^\[]+)\[\]$/', $class, $match)) { + $message = $this->processType($messageDefinition->getReturn()->getPhpType(), $message, $definitionComplexTypes); + + return $message; + } + + private function processType($phpType, $message, array $definitionComplexTypes) + { + if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) { $isArray = true; - $type = - $class = $match[1]; + $type = $match[1]; } else { $isArray = false; - $type = $return->getPhpType(); + $type = $phpType; } if (isset($definitionComplexTypes[$type])) { - if ($class[0] == '\\') { - $class = substr($class, 1); - } - if ($isArray) { $array = array(); foreach ($message as $complexType) { - $array[] = $this->getInstanceOfStdClass($type, $class, $complexType, $definitionComplexTypes); + $array[] = $this->getInstanceOfStdClass($type, $complexType, $definitionComplexTypes); } $message = $array; } else { - $message = $this->getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes); + $message = $this->getInstanceOfStdClass($type, $message, $definitionComplexTypes); } } return $message; } - private function getInstanceOfStdClass($type, $class, $message, $definitionComplexTypes) + private function getInstanceOfStdClass($phpType, $message, $definitionComplexTypes) { - if (get_class($message) !== $class) { - throw new \InvalidArgumentException(); - } - $hash = spl_object_hash($message); if (isset($this->messageRefs[$hash])) { return $this->messageRefs[$hash]; } + $class = $phpType; + if ($class[0] == '\\') { + $class = substr($class, 1); + } + + if (get_class($message) !== $class) { + throw new \InvalidArgumentException(); + } + $stdClass = new \stdClass(); $this->messageRefs[$hash] = $stdClass; - foreach ($definitionComplexTypes[$type] as $type) { + foreach ($definitionComplexTypes[$phpType] as $type) { + if ($type instanceof PropertyComplexType) { - $stdClass->{$type->getName()} = $message->{$type->getOriginalName()}; + $value = $message->{$type->getOriginalName()}; } elseif ($type instanceof MethodComplexType) { - $stdClass->{$type->getName()} = $message->{$type->getOriginalName()}(); + $value = $message->{$type->getOriginalName()}(); } else { throw new \InvalidArgumentException(); } + + $stdClass->{$type->getName()} = $this->processType($type->getValue(), $value, $definitionComplexTypes); } return $stdClass; From 9c2dd31b681529435caa3f4a8d3540ec986baca1 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 28 Jul 2011 00:39:55 +0200 Subject: [PATCH 12/16] Added unit tests --- .../RpcLiteralResponseMessageBinderTest.php | 86 ++++++++++++++++++- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php index 2ccb4ea..bc6129f 100644 --- a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php @@ -17,6 +17,8 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; use BeSimple\SoapBundle\ServiceBinding\RpcLiteralResponseMessageBinder; use BeSimple\SoapBundle\Util\Collection; use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes; +use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType; +use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters; /** * UnitTest for \BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder. @@ -36,10 +38,6 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame($assert, $result); } - /** - * @TODO test with complex type into complex type - * @TODO test setter and getter - */ public function testProcessMessageWithComplexType() { $definitionComplexTypes = $this->getDefinitionComplexTypes(); @@ -83,6 +81,56 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase $this->assertSame(123992, $result[1]->bar); } + public function testProcessMessageWithComplexTypeMethods() + { + $setters = new Setters(); + $setters->setFoo('foobar'); + $setters->setBar(42); + + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_methods', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')), + $setters, + $this->getDefinitionComplexTypes() + ); + + $this->assertInstanceOf('stdClass', $result); + $this->assertSame('foobar', $result->foo); + $this->assertSame(42, $result->bar); + } + + public function testProcessMessageWithComplexTypeIntoComplexType() + { + $complexType = new ComplexType(); + + $foo = new Attributes(); + $foo->foo = 'Hello world!'; + $foo->bar = 4242; + $complexType->setFoo($foo); + + $bar = new Setters(); + $bar->setFoo('bar foo'); + $bar->setBar(2424); + $complexType->bar = $bar; + + $messageBinder = new RpcLiteralResponseMessageBinder(); + $result = $messageBinder->processMessage( + new Method('complextype_complextype', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')), + $complexType, + $this->getDefinitionComplexTypes() + ); + + $this->assertInstanceOf('stdClass', $result); + + $this->assertInstanceOf('stdClass', $result->foo); + $this->assertSame('Hello world!', $result->foo->foo); + $this->assertSame(4242, $result->foo->bar); + + $this->assertInstanceOf('stdClass', $result->bar); + $this->assertSame('bar foo', $result->bar->foo); + $this->assertSame(2424, $result->bar->bar); + } + public function testProcessMessageWithComplexTypeReferences() { $attributes = new Attributes(); @@ -129,6 +177,19 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase array('bar', 'int'), )); + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'] = $this->createMethodsCollection(array( + array('foo', 'string', 'getFoo', 'setFoo'), + array('bar', 'int', 'getBar', 'setBar'), + )); + + $collection = $this->createMethodsCollection(array( + array('foo', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', 'getFoo', 'setFoo'), + )); + $this->createPropertiesCollection(array( + array('bar', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'), + ), $collection); + $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType'] = $collection; + return $this->definitionComplexTypes; } @@ -146,4 +207,21 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase return $collection; } + + private function createMethodsCollection(array $methods, Collection $collection = null) + { + $collection = $collection ?: new Collection('getName'); + + foreach ($methods as $method) { + $collectionMethod = new MethodComplexType(); + $collectionMethod->setName($method[0]); + $collectionMethod->setValue($method[1]); + $collectionMethod->setOriginalName($method[2]); + $collectionMethod->setSetter($method[3]); + + $collection->add($collectionMethod); + } + + return $collection; + } } From c4217ce816c05813a8f92307e802a8338dfef7ac Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Tue, 2 Aug 2011 23:27:56 +0200 Subject: [PATCH 13/16] Added RST documentation --- Resources/doc/_static/.gitkeep | 0 Resources/doc/conf.py | 226 ++++++++++++++++++++++ Resources/doc/index.rst | 27 +++ Resources/doc/reference/configuration.rst | 51 +++++ Resources/doc/reference/installation.rst | 65 +++++++ Resources/doc/tutorial/array.rst | 26 +++ Resources/doc/tutorial/complex_type.rst | 120 ++++++++++++ 7 files changed, 515 insertions(+) create mode 100644 Resources/doc/_static/.gitkeep create mode 100644 Resources/doc/conf.py create mode 100644 Resources/doc/index.rst create mode 100644 Resources/doc/reference/configuration.rst create mode 100644 Resources/doc/reference/installation.rst create mode 100644 Resources/doc/tutorial/array.rst create mode 100644 Resources/doc/tutorial/complex_type.rst diff --git a/Resources/doc/_static/.gitkeep b/Resources/doc/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/doc/conf.py b/Resources/doc/conf.py new file mode 100644 index 0000000..fcbd938 --- /dev/null +++ b/Resources/doc/conf.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +# +# BeSimpleSoapBundle documentation build configuration file, created by +# sphinx-quickstart on Mon Aug 1 22:24:10 2011. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +from sphinx.highlighting import lexers +from pygments.lexers.web import PhpLexer +lexers['php'] = PhpLexer(startinline=True) + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) +sys.path.append(os.path.abspath('_exts')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'BeSimpleSoapBundle' +copyright = u'2011, Christian Kerl, Francis Besset' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.0.0' +# The full version, including alpha/beta/rc tags. +release = '1.0.0-DEV' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +#pygments_style = 'sphinx' +pygments_style = 'perldoc' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'BeSimpleSoapBundledoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'BeSimpleSoapBundle.tex', u'BeSimpleSoapBundle Documentation', + u'Christian Kerl, Francis Besset', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'besimplesoapbundle', u'BeSimpleSoapBundle Documentation', + [u'Christian Kerl, Francis Besset'], 1) +] + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst new file mode 100644 index 0000000..d272f45 --- /dev/null +++ b/Resources/doc/index.rst @@ -0,0 +1,27 @@ +BeSimpleSoapBundle +================== + +The BeSimpleSoapBundle is a Symfony2 bundle to build WSDL and SOAP based web services. +It is based on the `ckWebServicePlugin`_ for symfony. + +Reference Guide +--------------- + +.. toctree:: + :maxdepth: 1 + :numbered: + + reference/installation + reference/configuration + +Tutorial +-------- + +.. toctree:: + :maxdepth: 1 + :numbered: + + tutorial/complex_type + tutorial/array + +.. _`ckWebServicePlugin`: http://www.symfony-project.org/plugins/ckWebServicePlugin \ No newline at end of file diff --git a/Resources/doc/reference/configuration.rst b/Resources/doc/reference/configuration.rst new file mode 100644 index 0000000..4c2d469 --- /dev/null +++ b/Resources/doc/reference/configuration.rst @@ -0,0 +1,51 @@ +Configuration +============= + +Routing +------- + +Include the `BeSimpleSoapBundle`'s routing configuration in your routing file (you can choose the prefix arbitrarily): + +.. code-block:: yaml + + # app/config/routing.yml + _besimple_soap: + resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml" + prefix: /ws + +Config +------ + +Configure your first web service in your config file: + +.. code-block:: yaml + + # app/config/config.yml + be_simple_soap: + services: + DemoApi: + namespace: http://mysymfonyapp.com/ws/DemoApi/1.0/ + binding: rpc-literal + resource: "@AcmeDemoBundle/Controller/DemoController.php" + resource_type: annotation + +Annotations for Controllers +--------------------------- + +.. code-block:: php + + use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; + use BeSimple\SoapBundle\Soap\SoapResponse; + + class DemoController extends Controller + { + /** + * @Soap\Method("Hello") + * @Soap\Param("name", phpType = "string") + * @Soap\Result(phpType = "string") + */ + public function helloAction($name) + { + return new SoapResponse(sprintf('Hello %s!', $name)); + } + } \ No newline at end of file diff --git a/Resources/doc/reference/installation.rst b/Resources/doc/reference/installation.rst new file mode 100644 index 0000000..69b5d70 --- /dev/null +++ b/Resources/doc/reference/installation.rst @@ -0,0 +1,65 @@ +Installation +============ + +Requirements +------------ + +Install and enable PHP's SOAP extension +Download `Zend\Soap`_ or add in `deps` file + +.. code-block:: ini + + ; deps file + [Zend\Soap] + git=http://github.com/BeSimple/zend-soap.git + target=/zend-framework/library/Zend/Soap + +Add Zend\Soap library in autoload.php + +.. code-block:: php + + // app/autoload.php + $loader->registerNamespaces(array( + 'ZendSoap' => __DIR__.'/../vendor/zend-framework/library', + // your other namespaces + )); + +Installation +------------ + +`Download`_ the bundle or add in `deps` file + +.. code-block:: ini + + ; deps file + [BeSimpleSoapBundle] + git=http://github.com/BeSimple/BeSimpleSoapBundle.git + target=/bundles/BeSimple/SoapBundle + +Add `BeSimple` in autoload.php + +.. code-block:: php + + // app/autoload.php + $loader->registerNamespaces(array( + 'BeSimple' => __DIR__.'/../vendor/bundles', + // your other namespaces + )); + +Add `BeSimpleSoapBundle` in your Kernel class + +.. code-block:: php + + // app/AppKernel.php + public function registerBundles() + { + return array( + // ... + new new BeSimple\SoapBundle\BeSimpleSoapBundle(), + // ... + ); + } + + +.. _`Zend\Soap`: http://github.com/BeSimple/zend-soap +.. _`Download`: http://github.com/BeSimple/BeSimpleSoapBundle \ No newline at end of file diff --git a/Resources/doc/tutorial/array.rst b/Resources/doc/tutorial/array.rst new file mode 100644 index 0000000..32b28ff --- /dev/null +++ b/Resources/doc/tutorial/array.rst @@ -0,0 +1,26 @@ +Array +===== + +Controller +---------- + +.. code-block:: php + + namespace My\App\Controller; + + use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; + use BeSimple\SoapBundle\Soap\SoapResponse; + use Symfony\Component\DependencyInjection\ContainerAware; + + class DemoController extends ContainerAware + { + /** + * @Soap\Method("isString") + * @Soap\Param("strings", phpType = "string[]") + * @Soap\Result(phpType = "boolean") + */ + public function helloAction(array $strings) + { + return new SoapResponse(true); + } + } \ No newline at end of file diff --git a/Resources/doc/tutorial/complex_type.rst b/Resources/doc/tutorial/complex_type.rst new file mode 100644 index 0000000..de60eb8 --- /dev/null +++ b/Resources/doc/tutorial/complex_type.rst @@ -0,0 +1,120 @@ +Complex Type +============ + +This tutorial explains how to do to return a complex type. + +If your SOAP function takes a complex type as input, this tutorial is +valid. You'll just have to adapt the input parameters of your method. + + +Controller +---------- + +.. code-block:: php + + namespace My\App\Controller; + + use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; + use BeSimple\SoapBundle\Soap\SoapResponse; + use Symfony\Component\DependencyInjection\ContainerAware; + + class DemoController extends ContainerAware + { + /** + * @Soap\Method("getUser") + * @Soap\Param("name", phpType = "string") + * + * Specify \My\App\Entity\User phpType + * Warning: Do not forget the first backslash + * @Soap\Result(phpType = "\My\App\Entity\User") + */ + public function getUserAction($name) + { + $user = $this->container->getDoctrine()->getRepository('MyApp:User')->findOneByName($name); + + if (!$user) { + throw new \SoapFault('USER_NOT_FOUND', sprintf('The user with the name "%s" can not be found', $name)); + } + + return new SoapResponse($user); + } + } + +User class +---------- + +You can expose public property and public method (getter and setter). + +.. code-block:: php + + namespace My\App\Entity; + + use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; + + class User + { + /** + * @Soap\PropertyComplexType("string") + */ + public $firstname; + + /** + * @Soap\PropertyComplexType("string") + */ + public $lastname; + + private $id; + private $username; + private $email; + + /** + * @Soap\MethodComplexType("int", name="user_id", nillable=true) + */ + public function getId() + { + return $this->id; + } + + /** + * @Soap\MethodComplexType("string", setter="setUsername") + */ + public function getUsername() + { + return $this->username; + } + + /** + * @Soap\MethodComplexType("string", setter="setEmail") + */ + public function getEmail() + { + return $this->email; + } + + public function setUsername($username) + { + $this->username = $username; + } + + public function setEmail($email) + { + $this->email = $email; + } + } + +PropertyComplexType +------------------- + +`PropertyComplexType` accepts the following options: + + * **name**: To override the original name of the property + * **nillable**: To specify that the value can be null + +MethodComplexType +------------------- + +`MethodComplexType` accepts the following options: + + * **name**: To override the original name of the property + * **nillable**: To specify that the value can be null + * **setter**: The set method name value. *Mandatory if the complex type is passed as a parameter to a function.* \ No newline at end of file From de94580403f5ae11e20ca0857248b2f8c85238db Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 4 Aug 2011 10:57:41 +0300 Subject: [PATCH 14/16] [Doc] Moved array in first tutorial --- Resources/doc/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst index d272f45..07ac795 100644 --- a/Resources/doc/index.rst +++ b/Resources/doc/index.rst @@ -21,7 +21,7 @@ Tutorial :maxdepth: 1 :numbered: - tutorial/complex_type tutorial/array + tutorial/complex_type .. _`ckWebServicePlugin`: http://www.symfony-project.org/plugins/ckWebServicePlugin \ No newline at end of file From b843acbec7774bd8d44b413647aa44a1fa6a0551 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 7 Aug 2011 11:33:34 +0200 Subject: [PATCH 15/16] Replaced zf2 by zend-soap and zend-mime of BeSimple Repository --- Tests/bootstrap.php | 2 +- phpunit.xml.dist | 4 ++-- vendors.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 8fa8a1e..4d7062a 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -22,4 +22,4 @@ spl_autoload_register(function($class) { return false; } -}); \ No newline at end of file +}); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4024132..c40be1e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ > - + @@ -21,4 +21,4 @@ ./Tests - \ No newline at end of file + diff --git a/vendors.php b/vendors.php index 3c473b8..098bddc 100755 --- a/vendors.php +++ b/vendors.php @@ -23,7 +23,8 @@ if (!is_dir($vendorDir = dirname(__FILE__).'/vendor')) { $deps = array( array('symfony', 'http://github.com/symfony/symfony.git', 'origin/HEAD'), - array('zend', 'http://github.com/zendframework/zf2.git', 'origin/HEAD'), + array('zend-framework/library/Zend/Soap', 'http://github.com/BeSimple/zend-soap.git', 'origin/HEAD'), + array('zend-framework/library/Zend/Mime', 'http://github.com/BeSimple/zend-mime.git', 'origin/HEAD'), ); foreach ($deps as $dep) { From b945632dcf86311eb77cb07a2ff649f1c6600755 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 7 Aug 2011 11:34:00 +0200 Subject: [PATCH 16/16] [Doc] Updated installation --- Resources/doc/reference/installation.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Resources/doc/reference/installation.rst b/Resources/doc/reference/installation.rst index 69b5d70..9711348 100644 --- a/Resources/doc/reference/installation.rst +++ b/Resources/doc/reference/installation.rst @@ -5,7 +5,7 @@ Requirements ------------ Install and enable PHP's SOAP extension -Download `Zend\Soap`_ or add in `deps` file +Download `Zend\\Soap`_ and `Zend\\Mime`_ or add in `deps` file .. code-block:: ini @@ -14,13 +14,17 @@ Download `Zend\Soap`_ or add in `deps` file git=http://github.com/BeSimple/zend-soap.git target=/zend-framework/library/Zend/Soap -Add Zend\Soap library in autoload.php + [Zend\Mime] + git=http://github.com/BeSimple/zend-mime.git + target=/zend-framework/library/Zend/Mime + +Add `Zend` library in autoload.php .. code-block:: php // app/autoload.php $loader->registerNamespaces(array( - 'ZendSoap' => __DIR__.'/../vendor/zend-framework/library', + 'Zend' => __DIR__.'/../vendor/zend-framework/library', // your other namespaces )); @@ -61,5 +65,6 @@ Add `BeSimpleSoapBundle` in your Kernel class } -.. _`Zend\Soap`: http://github.com/BeSimple/zend-soap -.. _`Download`: http://github.com/BeSimple/BeSimpleSoapBundle \ No newline at end of file +.. _`Zend\\Soap`: http://github.com/BeSimple/zend-soap +.. _`Zend\\Mime`: http://github.com/BeSimple/zend-mime +.. _`Download`: http://github.com/BeSimple/BeSimpleSoapBundle