|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00032 class Zend_Server_Method_Prototype 00033 { 00037 protected $_returnType = 'void'; 00038 00042 protected $_parameterNameMap = array(); 00043 00047 protected $_parameters = array(); 00048 00055 public function __construct($options = null) 00056 { 00057 if ((null !== $options) && is_array($options)) { 00058 $this->setOptions($options); 00059 } 00060 } 00061 00068 public function setReturnType($returnType) 00069 { 00070 $this->_returnType = $returnType; 00071 return $this; 00072 } 00073 00079 public function getReturnType() 00080 { 00081 return $this->_returnType; 00082 } 00083 00090 public function addParameter($parameter) 00091 { 00092 if ($parameter instanceof Zend_Server_Method_Parameter) { 00093 $this->_parameters[] = $parameter; 00094 if (null !== ($name = $parameter->getName())) { 00095 $this->_parameterNameMap[$name] = count($this->_parameters) - 1; 00096 } 00097 } else { 00098 require_once 'Zend/Server/Method/Parameter.php'; 00099 $parameter = new Zend_Server_Method_Parameter(array( 00100 'type' => (string) $parameter, 00101 )); 00102 $this->_parameters[] = $parameter; 00103 } 00104 return $this; 00105 } 00106 00113 public function addParameters(array $parameters) 00114 { 00115 foreach ($parameters as $parameter) { 00116 $this->addParameter($parameter); 00117 } 00118 return $this; 00119 } 00120 00127 public function setParameters(array $parameters) 00128 { 00129 $this->_parameters = array(); 00130 $this->_parameterNameMap = array(); 00131 $this->addParameters($parameters); 00132 return $this; 00133 } 00134 00140 public function getParameters() 00141 { 00142 $types = array(); 00143 foreach ($this->_parameters as $parameter) { 00144 $types[] = $parameter->getType(); 00145 } 00146 return $types; 00147 } 00148 00154 public function getParameterObjects() 00155 { 00156 return $this->_parameters; 00157 } 00158 00165 public function getParameter($index) 00166 { 00167 if (!is_string($index) && !is_numeric($index)) { 00168 return null; 00169 } 00170 if (array_key_exists($index, $this->_parameterNameMap)) { 00171 $index = $this->_parameterNameMap[$index]; 00172 } 00173 if (array_key_exists($index, $this->_parameters)) { 00174 return $this->_parameters[$index]; 00175 } 00176 return null; 00177 } 00178 00185 public function setOptions(array $options) 00186 { 00187 foreach ($options as $key => $value) { 00188 $method = 'set' . ucfirst($key); 00189 if (method_exists($this, $method)) { 00190 $this->$method($value); 00191 } 00192 } 00193 return $this; 00194 } 00195 00201 public function toArray() 00202 { 00203 return array( 00204 'returnType' => $this->getReturnType(), 00205 'parameters' => $this->getParameters(), 00206 ); 00207 } 00208 }