Issues

ZF-5202: Add Zend_Soap_Wsdl_Strategy_Composite

Issue Type: New Feature Created: 2008-12-10T10:39:52.000+0000 Last Updated: 2009-01-21T03:06:39.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Jordan Raub (ludicruz) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Soap_Wsdl

Related issues: Attachments:

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

<pre class="highlight">
class ReturnClass
{
    /**
     * @var string[]
     */
    public $firstName = array();

    /**
     * @var string[]
     */
    public $lastName = array();

    /**
     * @var string[]
     */
    public $email = array();
}



<pre class="highlight">
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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts