|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00022 require_once 'Zend/Server/Interface.php'; 00023 00027 require_once 'Zend/Server/Definition.php'; 00028 00032 require_once 'Zend/Server/Method/Definition.php'; 00033 00037 require_once 'Zend/Server/Method/Callback.php'; 00038 00042 require_once 'Zend/Server/Method/Prototype.php'; 00043 00047 require_once 'Zend/Server/Method/Parameter.php'; 00048 00058 abstract class Zend_Server_Abstract implements Zend_Server_Interface 00059 { 00064 protected static $magic_methods = array( 00065 '__call', 00066 '__clone', 00067 '__construct', 00068 '__destruct', 00069 '__get', 00070 '__isset', 00071 '__set', 00072 '__set_state', 00073 '__sleep', 00074 '__tostring', 00075 '__unset', 00076 '__wakeup', 00077 ); 00078 00082 protected $_overwriteExistingMethods = false; 00083 00087 protected $_table; 00088 00096 public function __construct() 00097 { 00098 $this->_table = new Zend_Server_Definition(); 00099 $this->_table->setOverwriteExistingMethods($this->_overwriteExistingMethods); 00100 } 00101 00109 public function getFunctions() 00110 { 00111 return $this->_table; 00112 } 00113 00124 public static function lowerCase(&$value, &$key) 00125 { 00126 trigger_error(__CLASS__ . '::' . __METHOD__ . '() is deprecated and will be removed in a future version', E_USER_NOTICE); 00127 return $value = strtolower($value); 00128 } 00129 00136 protected function _buildCallback(Zend_Server_Reflection_Function_Abstract $reflection) 00137 { 00138 $callback = new Zend_Server_Method_Callback(); 00139 if ($reflection instanceof Zend_Server_Reflection_Method) { 00140 $callback->setType($reflection->isStatic() ? 'static' : 'instance') 00141 ->setClass($reflection->getDeclaringClass()->getName()) 00142 ->setMethod($reflection->getName()); 00143 } elseif ($reflection instanceof Zend_Server_Reflection_Function) { 00144 $callback->setType('function') 00145 ->setFunction($reflection->getName()); 00146 } 00147 return $callback; 00148 } 00149 00158 protected function _buildSignature(Zend_Server_Reflection_Function_Abstract $reflection, $class = null) 00159 { 00160 $ns = $reflection->getNamespace(); 00161 $name = $reflection->getName(); 00162 $method = empty($ns) ? $name : $ns . '.' . $name; 00163 00164 if (!$this->_overwriteExistingMethods && $this->_table->hasMethod($method)) { 00165 require_once 'Zend/Server/Exception.php'; 00166 throw new Zend_Server_Exception('Duplicate method registered: ' . $method); 00167 } 00168 00169 $definition = new Zend_Server_Method_Definition(); 00170 $definition->setName($method) 00171 ->setCallback($this->_buildCallback($reflection)) 00172 ->setMethodHelp($reflection->getDescription()) 00173 ->setInvokeArguments($reflection->getInvokeArguments()); 00174 00175 foreach ($reflection->getPrototypes() as $proto) { 00176 $prototype = new Zend_Server_Method_Prototype(); 00177 $prototype->setReturnType($this->_fixType($proto->getReturnType())); 00178 foreach ($proto->getParameters() as $parameter) { 00179 $param = new Zend_Server_Method_Parameter(array( 00180 'type' => $this->_fixType($parameter->getType()), 00181 'name' => $parameter->getName(), 00182 'optional' => $parameter->isOptional(), 00183 )); 00184 if ($parameter->isDefaultValueAvailable()) { 00185 $param->setDefaultValue($parameter->getDefaultValue()); 00186 } 00187 $prototype->addParameter($param); 00188 } 00189 $definition->addPrototype($prototype); 00190 } 00191 if (is_object($class)) { 00192 $definition->setObject($class); 00193 } 00194 $this->_table->addMethod($definition); 00195 return $definition; 00196 } 00197 00205 protected function _dispatch(Zend_Server_Method_Definition $invocable, array $params) 00206 { 00207 $callback = $invocable->getCallback(); 00208 $type = $callback->getType(); 00209 00210 if ('function' == $type) { 00211 $function = $callback->getFunction(); 00212 return call_user_func_array($function, $params); 00213 } 00214 00215 $class = $callback->getClass(); 00216 $method = $callback->getMethod(); 00217 00218 if ('static' == $type) { 00219 return call_user_func_array(array($class, $method), $params); 00220 } 00221 00222 $object = $invocable->getObject(); 00223 if (!is_object($object)) { 00224 $invokeArgs = $invocable->getInvokeArguments(); 00225 if (!empty($invokeArgs)) { 00226 $reflection = new ReflectionClass($class); 00227 $object = $reflection->newInstanceArgs($invokeArgs); 00228 } else { 00229 $object = new $class; 00230 } 00231 } 00232 return call_user_func_array(array($object, $method), $params); 00233 } 00234 00241 abstract protected function _fixType($type); 00242 }