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.
This commit is contained in:
@ -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()));
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user