2011-07-17 15:04:33 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2011-07-17 15:04:33 +02:00
|
|
|
*
|
|
|
|
* (c) Christian Kerl <christian-kerl@web.de>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
2011-07-17 15:04:33 +02:00
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType;
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\Util\String;
|
2011-07-17 15:04:33 +02:00
|
|
|
|
|
|
|
use Zend\Soap\Exception;
|
2011-08-14 18:00:28 +02:00
|
|
|
use Zend\Soap\Wsdl as BaseWsdl;
|
2011-07-17 15:04:33 +02:00
|
|
|
use Zend\Soap\Wsdl\Strategy;
|
|
|
|
use Zend\Soap\Wsdl\Strategy\ArrayOfTypeSequence;
|
|
|
|
|
|
|
|
class WsdlTypeStrategy implements Strategy
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Context WSDL file
|
|
|
|
*
|
|
|
|
* @var \Zend\Soap\Wsdl|null
|
|
|
|
*/
|
|
|
|
private $context;
|
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
private $loader;
|
|
|
|
private $definition;
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
private $typeStrategy;
|
|
|
|
private $arrayStrategy;
|
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
public function __construct(AnnotationComplexTypeLoader $loader, ServiceDefinition $definition)
|
2011-07-17 15:04:33 +02:00
|
|
|
{
|
2011-07-23 20:06:42 +02:00
|
|
|
$this->loader = $loader;
|
|
|
|
$this->definition = $definition;
|
2011-07-17 15:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method accepts the current WSDL context file.
|
|
|
|
*
|
|
|
|
* @param \Zend\Soap\Wsdl $context
|
|
|
|
*/
|
2011-08-14 18:00:28 +02:00
|
|
|
public function setContext(BaseWsdl $context)
|
2011-07-17 15:04:33 +02:00
|
|
|
{
|
|
|
|
$this->context = $context;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a complex type based on a strategy
|
|
|
|
*
|
|
|
|
* @param string $type
|
2011-07-23 20:06:42 +02:00
|
|
|
*
|
2011-07-17 15:04:33 +02:00
|
|
|
* @return string XSD type
|
2011-07-23 20:06:42 +02:00
|
|
|
*
|
|
|
|
* @throws \Zend\Soap\WsdlException
|
2011-07-17 15:04:33 +02:00
|
|
|
*/
|
|
|
|
public function addComplexType($type)
|
|
|
|
{
|
|
|
|
if (!$this->context) {
|
|
|
|
throw new \LogicException(sprintf('Cannot add complex type "%s", no context is set for this composite strategy.', $type));
|
|
|
|
}
|
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
$strategy = String::endsWith($type, '[]') ? $this->getArrayStrategy() : $this->getTypeStrategy();
|
2011-07-17 15:04:33 +02:00
|
|
|
|
|
|
|
return $strategy->addComplexType($type);
|
|
|
|
}
|
2011-07-23 20:06:42 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2011-07-17 15:04:33 +02:00
|
|
|
}
|