ZF-5202: Add Zend_Soap_Wsdl_Strategy_Composite
Description
I found the need to use multiple strategies for my WSDL strategy. This is because I had a class that was for my response which had an array of ints and I wanted that to show up instead of just array.
The default nature of this will always return something since the last strategy used is Zend_Soap_Wsdl_Strategy_AnyType
hope this is useful
class ReturnClass
{
/**
* @var string[]
*/
public $firstName = array();
/**
* @var string[]
*/
public $lastName = array();
/**
* @var string[]
*/
public $email = array();
}
class Zend_Soap_Wsdl_Strategy_Composite
extends Zend_Soap_Wsdl_Strategy_Abstract
{
protected $_strategies = array(
'Zend_Soap_Wsdl_Strategy_DefaultComplexType',
'Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex',
'Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence',
'Zend_Soap_Wsdl_Strategy_AnyType',
);
public function __construct(array $strategies = null)
{
$this->setStrategies($strategies);
}
public function setStrategies(array $strategies = null)
{
if (!empty($strategies)) {
foreach ($strategies as $strategy) {
if (!class_exists($strategy)) {
require_once "Zend_Soap_Wsdl_Exception";
throw new Zend_Soap_Wsdl_Exception(
"WSDL Strategy {$strategy} does not exist"
);
}
}
$this->_strategies = $strategies;
}
}
/**
* @param string $type class
* @return string XSD type for the given PHP type
*/
public function addComplexType($type)
{
$retval = false;
foreach ($this->_strategies as $strategy) {
try {
$strategy = new $strategy();
$strategy->setContext($this->getContext());
$retval = $strategy->addComplexType($type);
break;
} catch(Zend_Soap_Wsdl_Exception $e) {}
}
if(!$retval)
{
throw new Zend_Soap_Wsdl_Exception(
"{$type} cannot be converted to a XSD type"
);
}
return $retval;
}
}
Comments
Posted by Benjamin Eberlei (beberlei) on 2009-01-21T03:06:38.000+0000
I have added a composite strategy for Complex Type detection. It works different than your suggestion though. You instantiate the strategy, give it a default Strategy and a map of type => strategy pairs that overwrite the default choice.
Will be released with the next minor version.