File indexing completed on 2025-05-04 05:28:23
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Soap 0017 * @subpackage Wsdl 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Soap_Wsdl_Strategy_Interface 0025 */ 0026 // require_once "Zend/Soap/Wsdl/Strategy/Interface.php"; 0027 0028 /** 0029 * Zend_Soap_Wsdl_Strategy_Composite 0030 * 0031 * @category Zend 0032 * @package Zend_Soap 0033 * @subpackage Wsdl 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Soap_Wsdl_Strategy_Composite implements Zend_Soap_Wsdl_Strategy_Interface 0038 { 0039 /** 0040 * Typemap of Complex Type => Strategy pairs. 0041 * 0042 * @var array 0043 */ 0044 protected $_typeMap = array(); 0045 0046 /** 0047 * Default Strategy of this composite 0048 * 0049 * @var string|Zend_Soap_Wsdl_Strategy_Interface 0050 */ 0051 protected $_defaultStrategy; 0052 0053 /** 0054 * Context WSDL file that this composite serves 0055 * 0056 * @var Zend_Soap_Wsdl|null 0057 */ 0058 protected $_context; 0059 0060 /** 0061 * Construct Composite WSDL Strategy. 0062 * 0063 * @throws Zend_Soap_Wsdl_Exception 0064 * @param array $typeMap 0065 * @param string|Zend_Soap_Wsdl_Strategy_Interface $defaultStrategy 0066 */ 0067 public function __construct(array $typeMap=array(), $defaultStrategy="Zend_Soap_Wsdl_Strategy_DefaultComplexType") 0068 { 0069 foreach($typeMap AS $type => $strategy) { 0070 $this->connectTypeToStrategy($type, $strategy); 0071 } 0072 $this->_defaultStrategy = $defaultStrategy; 0073 } 0074 0075 /** 0076 * Connect a complex type to a given strategy. 0077 * 0078 * @throws Zend_Soap_Wsdl_Exception 0079 * @param string $type 0080 * @param string|Zend_Soap_Wsdl_Strategy_Interface $strategy 0081 * @return Zend_Soap_Wsdl_Strategy_Composite 0082 */ 0083 public function connectTypeToStrategy($type, $strategy) 0084 { 0085 if(!is_string($type)) { 0086 /** 0087 * @see Zend_Soap_Wsdl_Exception 0088 */ 0089 // require_once "Zend/Soap/Wsdl/Exception.php"; 0090 throw new Zend_Soap_Wsdl_Exception("Invalid type given to Composite Type Map."); 0091 } 0092 $this->_typeMap[$type] = $strategy; 0093 return $this; 0094 } 0095 0096 /** 0097 * Return default strategy of this composite 0098 * 0099 * @throws Zend_Soap_Wsdl_Exception 0100 * @param string $type 0101 * @return Zend_Soap_Wsdl_Strategy_Interface 0102 */ 0103 public function getDefaultStrategy() 0104 { 0105 $strategy = $this->_defaultStrategy; 0106 if(is_string($strategy) && class_exists($strategy)) { 0107 $strategy = new $strategy; 0108 } 0109 if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) { 0110 /** 0111 * @see Zend_Soap_Wsdl_Exception 0112 */ 0113 // require_once "Zend/Soap/Wsdl/Exception.php"; 0114 throw new Zend_Soap_Wsdl_Exception( 0115 "Default Strategy for Complex Types is not a valid strategy object." 0116 ); 0117 } 0118 $this->_defaultStrategy = $strategy; 0119 return $strategy; 0120 } 0121 0122 /** 0123 * Return specific strategy or the default strategy of this type. 0124 * 0125 * @throws Zend_Soap_Wsdl_Exception 0126 * @param string $type 0127 * @return Zend_Soap_Wsdl_Strategy_Interface 0128 */ 0129 public function getStrategyOfType($type) 0130 { 0131 if(isset($this->_typeMap[$type])) { 0132 $strategy = $this->_typeMap[$type]; 0133 0134 if(is_string($strategy) && class_exists($strategy)) { 0135 $strategy = new $strategy(); 0136 } 0137 0138 if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) { 0139 /** 0140 * @see Zend_Soap_Wsdl_Exception 0141 */ 0142 // require_once "Zend/Soap/Wsdl/Exception.php"; 0143 throw new Zend_Soap_Wsdl_Exception( 0144 "Strategy for Complex Type '".$type."' is not a valid strategy object." 0145 ); 0146 } 0147 $this->_typeMap[$type] = $strategy; 0148 } else { 0149 $strategy = $this->getDefaultStrategy(); 0150 } 0151 return $strategy; 0152 } 0153 0154 /** 0155 * Method accepts the current WSDL context file. 0156 * 0157 * @param Zend_Soap_Wsdl $context 0158 */ 0159 public function setContext(Zend_Soap_Wsdl $context) 0160 { 0161 $this->_context = $context; 0162 return $this; 0163 } 0164 0165 /** 0166 * Create a complex type based on a strategy 0167 * 0168 * @throws Zend_Soap_Wsdl_Exception 0169 * @param string $type 0170 * @return string XSD type 0171 */ 0172 public function addComplexType($type) 0173 { 0174 if(!($this->_context instanceof Zend_Soap_Wsdl) ) { 0175 /** 0176 * @see Zend_Soap_Wsdl_Exception 0177 */ 0178 // require_once "Zend/Soap/Wsdl/Exception.php"; 0179 throw new Zend_Soap_Wsdl_Exception( 0180 "Cannot add complex type '".$type."', no context is set for this composite strategy." 0181 ); 0182 } 0183 0184 $strategy = $this->getStrategyOfType($type); 0185 $strategy->setContext($this->_context); 0186 return $strategy->addComplexType($type); 0187 } 0188 }