|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00032 class Zend_Server_Method_Callback 00033 { 00037 protected $_class; 00038 00042 protected $_function; 00043 00047 protected $_method; 00048 00052 protected $_type; 00053 00057 protected $_types = array('function', 'static', 'instance'); 00058 00065 public function __construct($options = null) 00066 { 00067 if ((null !== $options) && is_array($options)) { 00068 $this->setOptions($options); 00069 } 00070 } 00071 00078 public function setOptions(array $options) 00079 { 00080 foreach ($options as $key => $value) { 00081 $method = 'set' . ucfirst($key); 00082 if (method_exists($this, $method)) { 00083 $this->$method($value); 00084 } 00085 } 00086 return $this; 00087 } 00088 00095 public function setClass($class) 00096 { 00097 if (is_object($class)) { 00098 $class = get_class($class); 00099 } 00100 $this->_class = $class; 00101 return $this; 00102 } 00103 00109 public function getClass() 00110 { 00111 return $this->_class; 00112 } 00113 00120 public function setFunction($function) 00121 { 00122 $this->_function = (string) $function; 00123 $this->setType('function'); 00124 return $this; 00125 } 00126 00132 public function getFunction() 00133 { 00134 return $this->_function; 00135 } 00136 00143 public function setMethod($method) 00144 { 00145 $this->_method = $method; 00146 return $this; 00147 } 00148 00154 public function getMethod() 00155 { 00156 return $this->_method; 00157 } 00158 00166 public function setType($type) 00167 { 00168 if (!in_array($type, $this->_types)) { 00169 require_once 'Zend/Server/Exception.php'; 00170 throw new Zend_Server_Exception('Invalid method callback type passed to ' . __CLASS__ . '::' . __METHOD__); 00171 } 00172 $this->_type = $type; 00173 return $this; 00174 } 00175 00181 public function getType() 00182 { 00183 return $this->_type; 00184 } 00185 00191 public function toArray() 00192 { 00193 $type = $this->getType(); 00194 $array = array( 00195 'type' => $type, 00196 ); 00197 if ('function' == $type) { 00198 $array['function'] = $this->getFunction(); 00199 } else { 00200 $array['class'] = $this->getClass(); 00201 $array['method'] = $this->getMethod(); 00202 } 00203 return $array; 00204 } 00205 }