[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Soap/Wsdl/Strategy/ -> Composite.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Soap
  17   * @subpackage Wsdl
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * @see Zend_Soap_Wsdl_Strategy_Interface
  25   */
  26  require_once "Zend/Soap/Wsdl/Strategy/Interface.php";
  27  
  28  /**
  29   * Zend_Soap_Wsdl_Strategy_Composite
  30   *
  31   * @category   Zend
  32   * @package    Zend_Soap
  33   * @subpackage Wsdl
  34   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  36   */
  37  class Zend_Soap_Wsdl_Strategy_Composite implements Zend_Soap_Wsdl_Strategy_Interface
  38  {
  39      /**
  40       * Typemap of Complex Type => Strategy pairs.
  41       *
  42       * @var array
  43       */
  44      protected $_typeMap = array();
  45  
  46      /**
  47       * Default Strategy of this composite
  48       *
  49       * @var string|Zend_Soap_Wsdl_Strategy_Interface
  50       */
  51      protected $_defaultStrategy;
  52  
  53      /**
  54       * Context WSDL file that this composite serves
  55       *
  56       * @var Zend_Soap_Wsdl|null
  57       */
  58      protected $_context;
  59  
  60      /**
  61       * Construct Composite WSDL Strategy.
  62       *
  63       * @throws Zend_Soap_Wsdl_Exception
  64       * @param array $typeMap
  65       * @param string|Zend_Soap_Wsdl_Strategy_Interface $defaultStrategy
  66       */
  67      public function __construct(array $typeMap=array(), $defaultStrategy="Zend_Soap_Wsdl_Strategy_DefaultComplexType")
  68      {
  69          foreach($typeMap AS $type => $strategy) {
  70              $this->connectTypeToStrategy($type, $strategy);
  71          }
  72          $this->_defaultStrategy = $defaultStrategy;
  73      }
  74  
  75      /**
  76       * Connect a complex type to a given strategy.
  77       *
  78       * @throws Zend_Soap_Wsdl_Exception
  79       * @param  string $type
  80       * @param  string|Zend_Soap_Wsdl_Strategy_Interface $strategy
  81       * @return Zend_Soap_Wsdl_Strategy_Composite
  82       */
  83      public function connectTypeToStrategy($type, $strategy)
  84      {
  85          if(!is_string($type)) {
  86              /**
  87               * @see Zend_Soap_Wsdl_Exception
  88               */
  89              require_once "Zend/Soap/Wsdl/Exception.php";
  90              throw new Zend_Soap_Wsdl_Exception("Invalid type given to Composite Type Map.");
  91          }
  92          $this->_typeMap[$type] = $strategy;
  93          return $this;
  94      }
  95  
  96      /**
  97       * Return default strategy of this composite
  98       *
  99       * @throws Zend_Soap_Wsdl_Exception
 100       * @param  string $type
 101       * @return Zend_Soap_Wsdl_Strategy_Interface
 102       */
 103      public function getDefaultStrategy()
 104      {
 105          $strategy = $this->_defaultStrategy;
 106          if(is_string($strategy) && class_exists($strategy)) {
 107              $strategy = new $strategy;
 108          }
 109          if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) {
 110              /**
 111               * @see Zend_Soap_Wsdl_Exception
 112               */
 113              require_once "Zend/Soap/Wsdl/Exception.php";
 114              throw new Zend_Soap_Wsdl_Exception(
 115                  "Default Strategy for Complex Types is not a valid strategy object."
 116              );
 117          }
 118          $this->_defaultStrategy = $strategy;
 119          return $strategy;
 120      }
 121  
 122      /**
 123       * Return specific strategy or the default strategy of this type.
 124       *
 125       * @throws Zend_Soap_Wsdl_Exception
 126       * @param  string $type
 127       * @return Zend_Soap_Wsdl_Strategy_Interface
 128       */
 129      public function getStrategyOfType($type)
 130      {
 131          if(isset($this->_typeMap[$type])) {
 132              $strategy = $this->_typeMap[$type];
 133  
 134              if(is_string($strategy) && class_exists($strategy)) {
 135                  $strategy = new $strategy();
 136              }
 137  
 138              if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) {
 139                  /**
 140                   * @see Zend_Soap_Wsdl_Exception
 141                   */
 142                  require_once "Zend/Soap/Wsdl/Exception.php";
 143                  throw new Zend_Soap_Wsdl_Exception(
 144                      "Strategy for Complex Type '".$type."' is not a valid strategy object."
 145                  );
 146              }
 147              $this->_typeMap[$type] = $strategy;
 148          } else {
 149              $strategy = $this->getDefaultStrategy();
 150          }
 151          return $strategy;
 152      }
 153  
 154      /**
 155       * Method accepts the current WSDL context file.
 156       *
 157       * @param Zend_Soap_Wsdl $context
 158       */
 159      public function setContext(Zend_Soap_Wsdl $context)
 160      {
 161          $this->_context = $context;
 162          return $this;
 163      }
 164  
 165      /**
 166       * Create a complex type based on a strategy
 167       *
 168       * @throws Zend_Soap_Wsdl_Exception
 169       * @param  string $type
 170       * @return string XSD type
 171       */
 172      public function addComplexType($type)
 173      {
 174          if(!($this->_context instanceof Zend_Soap_Wsdl) ) {
 175              /**
 176               * @see Zend_Soap_Wsdl_Exception
 177               */
 178              require_once "Zend/Soap/Wsdl/Exception.php";
 179              throw new Zend_Soap_Wsdl_Exception(
 180                  "Cannot add complex type '".$type."', no context is set for this composite strategy."
 181              );
 182          }
 183  
 184          $strategy = $this->getStrategyOfType($type);
 185          $strategy->setContext($this->_context);
 186          return $strategy->addComplexType($type);
 187      }
 188  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1