|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00031 class Zend_Server_Definition implements Countable, Iterator 00032 { 00036 protected $_methods = array(); 00037 00041 protected $_overwriteExistingMethods = false; 00042 00049 public function __construct($methods = null) 00050 { 00051 if (is_array($methods)) { 00052 $this->setMethods($methods); 00053 } 00054 } 00055 00062 public function setOverwriteExistingMethods($flag) 00063 { 00064 $this->_overwriteExistingMethods = (bool) $flag; 00065 return $this; 00066 } 00067 00076 public function addMethod($method, $name = null) 00077 { 00078 if (is_array($method)) { 00079 require_once 'Zend/Server/Method/Definition.php'; 00080 $method = new Zend_Server_Method_Definition($method); 00081 } elseif (!$method instanceof Zend_Server_Method_Definition) { 00082 require_once 'Zend/Server/Exception.php'; 00083 throw new Zend_Server_Exception('Invalid method provided'); 00084 } 00085 00086 if (is_numeric($name)) { 00087 $name = null; 00088 } 00089 if (null !== $name) { 00090 $method->setName($name); 00091 } else { 00092 $name = $method->getName(); 00093 } 00094 if (null === $name) { 00095 require_once 'Zend/Server/Exception.php'; 00096 throw new Zend_Server_Exception('No method name provided'); 00097 } 00098 00099 if (!$this->_overwriteExistingMethods && array_key_exists($name, $this->_methods)) { 00100 require_once 'Zend/Server/Exception.php'; 00101 throw new Zend_Server_Exception(sprintf('Method by name of "%s" already exists', $name)); 00102 } 00103 $this->_methods[$name] = $method; 00104 return $this; 00105 } 00106 00113 public function addMethods(array $methods) 00114 { 00115 foreach ($methods as $key => $method) { 00116 $this->addMethod($method, $key); 00117 } 00118 return $this; 00119 } 00120 00127 public function setMethods(array $methods) 00128 { 00129 $this->clearMethods(); 00130 $this->addMethods($methods); 00131 return $this; 00132 } 00133 00140 public function hasMethod($method) 00141 { 00142 return array_key_exists($method, $this->_methods); 00143 } 00144 00151 public function getMethod($method) 00152 { 00153 if ($this->hasMethod($method)) { 00154 return $this->_methods[$method]; 00155 } 00156 return false; 00157 } 00158 00164 public function getMethods() 00165 { 00166 return $this->_methods; 00167 } 00168 00175 public function removeMethod($method) 00176 { 00177 if ($this->hasMethod($method)) { 00178 unset($this->_methods[$method]); 00179 } 00180 return $this; 00181 } 00182 00188 public function clearMethods() 00189 { 00190 $this->_methods = array(); 00191 return $this; 00192 } 00193 00199 public function toArray() 00200 { 00201 $methods = array(); 00202 foreach ($this->getMethods() as $key => $method) { 00203 $methods[$key] = $method->toArray(); 00204 } 00205 return $methods; 00206 } 00207 00213 public function count() 00214 { 00215 return count($this->_methods); 00216 } 00217 00223 public function current() 00224 { 00225 return current($this->_methods); 00226 } 00227 00233 public function key() 00234 { 00235 return key($this->_methods); 00236 } 00237 00243 public function next() 00244 { 00245 return next($this->_methods); 00246 } 00247 00253 public function rewind() 00254 { 00255 return reset($this->_methods); 00256 } 00257 00263 public function valid() 00264 { 00265 return (bool) $this->current(); 00266 } 00267 }