File indexing completed on 2025-01-19 05:21:27
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_Server 0017 * @subpackage Method 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 * Method definition metadata 0025 * 0026 * @category Zend 0027 * @package Zend_Server 0028 * @subpackage Method 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 */ 0032 class Zend_Server_Method_Definition 0033 { 0034 /** 0035 * @var Zend_Server_Method_Callback 0036 */ 0037 protected $_callback; 0038 0039 /** 0040 * @var array 0041 */ 0042 protected $_invokeArguments = array(); 0043 0044 /** 0045 * @var string 0046 */ 0047 protected $_methodHelp = ''; 0048 0049 /** 0050 * @var string 0051 */ 0052 protected $_name; 0053 0054 /** 0055 * @var null|object 0056 */ 0057 protected $_object; 0058 0059 /** 0060 * @var array Array of Zend_Server_Method_Prototype objects 0061 */ 0062 protected $_prototypes = array(); 0063 0064 /** 0065 * Constructor 0066 * 0067 * @param null|array $options 0068 * @return void 0069 */ 0070 public function __construct($options = null) 0071 { 0072 if ((null !== $options) && is_array($options)) { 0073 $this->setOptions($options); 0074 } 0075 } 0076 0077 /** 0078 * Set object state from options 0079 * 0080 * @param array $options 0081 * @return Zend_Server_Method_Definition 0082 */ 0083 public function setOptions(array $options) 0084 { 0085 foreach ($options as $key => $value) { 0086 $method = 'set' . ucfirst($key); 0087 if (method_exists($this, $method)) { 0088 $this->$method($value); 0089 } 0090 } 0091 return $this; 0092 } 0093 0094 /** 0095 * Set method name 0096 * 0097 * @param string $name 0098 * @return Zend_Server_Method_Definition 0099 */ 0100 public function setName($name) 0101 { 0102 $this->_name = (string) $name; 0103 return $this; 0104 } 0105 0106 /** 0107 * Get method name 0108 * 0109 * @return string 0110 */ 0111 public function getName() 0112 { 0113 return $this->_name; 0114 } 0115 0116 /** 0117 * Set method callback 0118 * 0119 * @param array|Zend_Server_Method_Callback $callback 0120 * @return Zend_Server_Method_Definition 0121 */ 0122 public function setCallback($callback) 0123 { 0124 if (is_array($callback)) { 0125 // require_once 'Zend/Server/Method/Callback.php'; 0126 $callback = new Zend_Server_Method_Callback($callback); 0127 } elseif (!$callback instanceof Zend_Server_Method_Callback) { 0128 // require_once 'Zend/Server/Exception.php'; 0129 throw new Zend_Server_Exception('Invalid method callback provided'); 0130 } 0131 $this->_callback = $callback; 0132 return $this; 0133 } 0134 0135 /** 0136 * Get method callback 0137 * 0138 * @return Zend_Server_Method_Callback 0139 */ 0140 public function getCallback() 0141 { 0142 return $this->_callback; 0143 } 0144 0145 /** 0146 * Add prototype to method definition 0147 * 0148 * @param array|Zend_Server_Method_Prototype $prototype 0149 * @return Zend_Server_Method_Definition 0150 */ 0151 public function addPrototype($prototype) 0152 { 0153 if (is_array($prototype)) { 0154 // require_once 'Zend/Server/Method/Prototype.php'; 0155 $prototype = new Zend_Server_Method_Prototype($prototype); 0156 } elseif (!$prototype instanceof Zend_Server_Method_Prototype) { 0157 // require_once 'Zend/Server/Exception.php'; 0158 throw new Zend_Server_Exception('Invalid method prototype provided'); 0159 } 0160 $this->_prototypes[] = $prototype; 0161 return $this; 0162 } 0163 0164 /** 0165 * Add multiple prototypes at once 0166 * 0167 * @param array $prototypes Array of Zend_Server_Method_Prototype objects or arrays 0168 * @return Zend_Server_Method_Definition 0169 */ 0170 public function addPrototypes(array $prototypes) 0171 { 0172 foreach ($prototypes as $prototype) { 0173 $this->addPrototype($prototype); 0174 } 0175 return $this; 0176 } 0177 0178 /** 0179 * Set all prototypes at once (overwrites) 0180 * 0181 * @param array $prototypes Array of Zend_Server_Method_Prototype objects or arrays 0182 * @return Zend_Server_Method_Definition 0183 */ 0184 public function setPrototypes(array $prototypes) 0185 { 0186 $this->_prototypes = array(); 0187 $this->addPrototypes($prototypes); 0188 return $this; 0189 } 0190 0191 /** 0192 * Get all prototypes 0193 * 0194 * @return array $prototypes Array of Zend_Server_Method_Prototype objects or arrays 0195 */ 0196 public function getPrototypes() 0197 { 0198 return $this->_prototypes; 0199 } 0200 0201 /** 0202 * Set method help 0203 * 0204 * @param string $methodHelp 0205 * @return Zend_Server_Method_Definition 0206 */ 0207 public function setMethodHelp($methodHelp) 0208 { 0209 $this->_methodHelp = (string) $methodHelp; 0210 return $this; 0211 } 0212 0213 /** 0214 * Get method help 0215 * 0216 * @return string 0217 */ 0218 public function getMethodHelp() 0219 { 0220 return $this->_methodHelp; 0221 } 0222 0223 /** 0224 * Set object to use with method calls 0225 * 0226 * @param object $object 0227 * @return Zend_Server_Method_Definition 0228 */ 0229 public function setObject($object) 0230 { 0231 if (!is_object($object) && (null !== $object)) { 0232 // require_once 'Zend/Server/Exception.php'; 0233 throw new Zend_Server_Exception('Invalid object passed to ' . __CLASS__ . '::' . __METHOD__); 0234 } 0235 $this->_object = $object; 0236 return $this; 0237 } 0238 0239 /** 0240 * Get object to use with method calls 0241 * 0242 * @return null|object 0243 */ 0244 public function getObject() 0245 { 0246 return $this->_object; 0247 } 0248 0249 /** 0250 * Set invoke arguments 0251 * 0252 * @param array $invokeArguments 0253 * @return Zend_Server_Method_Definition 0254 */ 0255 public function setInvokeArguments(array $invokeArguments) 0256 { 0257 $this->_invokeArguments = $invokeArguments; 0258 return $this; 0259 } 0260 0261 /** 0262 * Retrieve invoke arguments 0263 * 0264 * @return array 0265 */ 0266 public function getInvokeArguments() 0267 { 0268 return $this->_invokeArguments; 0269 } 0270 0271 /** 0272 * Serialize to array 0273 * 0274 * @return array 0275 */ 0276 public function toArray() 0277 { 0278 $prototypes = $this->getPrototypes(); 0279 $signatures = array(); 0280 foreach ($prototypes as $prototype) { 0281 $signatures[] = $prototype->toArray(); 0282 } 0283 0284 return array( 0285 'name' => $this->getName(), 0286 'callback' => $this->getCallback()->toArray(), 0287 'prototypes' => $signatures, 0288 'methodHelp' => $this->getMethodHelp(), 0289 'invokeArguments' => $this->getInvokeArguments(), 0290 'object' => $this->getObject(), 0291 ); 0292 } 0293 }