⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * @param mixed $class     * @return void     */    public function setPersistence($class = null)    {    }    /**     * Attach class methods as XMLRPC method handlers     *     * $class may be either a class name or an object. Reflection is done on the     * class or object to determine the available public methods, and each is     * attached to the server as an available method; if a $namespace has been     * provided, that namespace is used to prefix the XMLRPC method names.     *     * Any additional arguments beyond $namespace will be passed to a method at     * invocation.     *     * @param string|object $class     * @param string $namespace Optional     * @param mixed $argv Optional arguments to pass to methods     * @return void     * @throws Zend_XmlRpc_Server_Exception on invalid input     */    public function setClass($class, $namespace = '', $argv = null)    {        if (is_string($class) && !class_exists($class)) {            if (!class_exists($class)) {                throw new Zend_XmlRpc_Server_Exception('Invalid method class', 610);            }        }        $argv = null;        if (3 < func_num_args()) {            $argv = func_get_args();            $argv = array_slice($argv, 3);        }        $this->_methods[] = Zend_Server_Reflection::reflectClass($class, $argv, $namespace);        $this->_buildDispatchTable();    }    /**     * Set the request object     *     * @param string|Zend_XmlRpc_Request $request     * @return Zend_XmlRpc_Server     * @throws Zend_XmlRpc_Server_Exception on invalid request class or object     */    public function setRequest($request)    {        if (is_string($request) && class_exists($request)) {            $request = new $request();            if (!$request instanceof Zend_XmlRpc_Request) {                throw new Zend_XmlRpc_Server_Exception('Invalid request class');            }            $request->setEncoding($this->getEncoding());        } elseif (!$request instanceof Zend_XmlRpc_Request) {            throw new Zend_XmlRpc_Server_Exception('Invalid request object');        }        $this->_request = $request;        return $this;    }    /**     * Return currently registered request object     *     * @return null|Zend_XmlRpc_Request     */    public function getRequest()    {        return $this->_request;    }    /**     * Raise an xmlrpc server fault     *     * @param string|Exception $fault     * @param int $code     * @return Zend_XmlRpc_Server_Fault     */    public function fault($fault, $code = 404)    {        if (!$fault instanceof Exception) {            $fault = (string) $fault;            $fault = new Zend_XmlRpc_Server_Exception($fault, $code);        }        return Zend_XmlRpc_Server_Fault::getInstance($fault);    }    /**     * Handle an xmlrpc call (actual work)     *     * @param Zend_XmlRpc_Request $request     * @return Zend_XmlRpc_Response     * @throws Zend_XmlRpcServer_Exception|Exception     * Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise,     * any other exception may be thrown by the callback     */    protected function _handle(Zend_XmlRpc_Request $request)    {        $method = $request->getMethod();        // Check for valid method        if (!isset($this->_table[$method])) {            throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 620);        }        $info     = $this->_table[$method];        $params   = $request->getParams();        $argv     = $info->getInvokeArguments();        if (0 < count($argv)) {            $params = array_merge($params, $argv);        }        // Check calling parameters against signatures        $matched    = false;        $sigCalled  = $request->getTypes();        $sigLength  = count($sigCalled);        $paramsLen  = count($params);        if ($sigLength < $paramsLen) {            for ($i = $sigLength; $i < $paramsLen; ++$i) {                $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($params[$i]);                $sigCalled[] = $xmlRpcValue->getType();            }        }        $signatures = $info->getPrototypes();        foreach ($signatures as $signature) {            $sigParams = $signature->getParameters();            $tmpParams = array();            foreach ($sigParams as $param) {                $tmpParams[] = $param->getType();            }            if ($sigCalled === $tmpParams) {                $matched = true;                break;            }        }        if (!$matched) {            throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623);        }        if ($info instanceof Zend_Server_Reflection_Function) {            $func = $info->getName();            $return = call_user_func_array($func, $params);        } elseif (($info instanceof Zend_Server_Reflection_Method) && $info->system) {            // System methods            $return = $info->invokeArgs($this, $params);        } elseif ($info instanceof Zend_Server_Reflection_Method) {            // Get class            $class = $info->getDeclaringClass()->getName();            if ('static' == $info->isStatic()) {                // for some reason, invokeArgs() does not work the same as                // invoke(), and expects the first argument to be an object.                // So, using a callback if the method is static.                $return = call_user_func_array(array($class, $info->getName()), $params);            } else {                // Object methods                try {                    $object = $info->getDeclaringClass()->newInstance();                } catch (Exception $e) {                    throw new Zend_XmlRpc_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName(), 621);                }                $return = $info->invokeArgs($object, $params);            }        } else {            throw new Zend_XmlRpc_Server_Exception('Method missing implementation ' . get_class($info), 622);        }        $response = new ReflectionClass($this->_responseClass);        return $response->newInstance($return);    }    /**     * Handle an xmlrpc call     *     * @param Zend_XmlRpc_Request $request Optional     * @return Zend_XmlRpc_Response|Zend_XmlRpc_Fault     */    public function handle(Zend_XmlRpc_Request $request = null)    {        // Get request        if ((null === $request) && (null === ($request = $this->getRequest()))) {            require_once 'Zend/XmlRpc/Request/Http.php';            $request = new Zend_XmlRpc_Request_Http();            $request->setEncoding($this->getEncoding());        }        $this->setRequest($request);        if ($request->isFault()) {            $response = $request->getFault();        } else {            try {                $response = $this->_handle($request);            } catch (Exception $e) {                $response = $this->fault($e);            }        }        // Set output encoding        $response->setEncoding($this->getEncoding());        return $response;    }    /**     * Set the class to use for the response     *     * @param string $class     * @return boolean True if class was set, false if not     */    public function setResponseClass($class)    {        if (class_exists($class)) {            $reflection = new ReflectionClass($class);            if ($reflection->isSubclassOf(new ReflectionClass('Zend_XmlRpc_Response'))) {                $this->_responseClass = $class;                return true;            }        }        return false;    }    /**     * Returns a list of registered methods     *     * Returns an array of dispatchables (Zend_Server_Reflection_Function,     * _Method, and _Class items).     *     * @return array     */    public function getFunctions()    {        $return = array();        foreach ($this->_methods as $method) {            if ($method instanceof Zend_Server_Reflection_Class                && ($method->system))            {                continue;            }            $return[] = $method;        }        return $return;    }    /**     * List all available XMLRPC methods     *     * Returns an array of methods.     *     * @return array     */    public function listMethods()    {        return array_keys($this->_table);    }    /**     * Display help message for an XMLRPC method     *     * @param string $method     * @return string     */    public function methodHelp($method)    {        if (!isset($this->_table[$method])) {            throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);        }        return $this->_table[$method]->getDescription();    }    /**     * Return a method signature     *     * @param string $method     * @return array     */    public function methodSignature($method)    {        if (!isset($this->_table[$method])) {            throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);        }        $prototypes = $this->_table[$method]->getPrototypes();        $signatures = array();        foreach ($prototypes as $prototype) {            $signature = array($prototype->getReturnType());            foreach ($prototype->getParameters() as $parameter) {                $signature[] = $parameter->getType();            }            $signatures[] = $signature;        }        return $signatures;    }    /**     * Multicall - boxcar feature of XML-RPC for calling multiple methods     * in a single request.     *     * Expects a an array of structs representing method calls, each element     * having the keys:     * - methodName     * - params     *     * Returns an array of responses, one for each method called, with the value     * returned by the method. If an error occurs for a given method, returns a     * struct with a fault response.     *     * @see http://www.xmlrpc.com/discuss/msgReader$1208     * @param  array $methods     * @return array     */    public function multicall($methods)    {        $responses = array();        foreach ($methods as $method) {            $fault = false;            if (!is_array($method)) {                $fault = $this->fault('system.multicall expects each method to be a struct', 601);            } elseif (!isset($method['methodName'])) {                $fault = $this->fault('Missing methodName', 602);            } elseif (!isset($method['params'])) {                $fault = $this->fault('Missing params', 603);            } elseif (!is_array($method['params'])) {                $fault = $this->fault('Params must be an array', 604);            } else {                if ('system.multicall' == $method['methodName']) {                    // don't allow recursive calls to multicall                    $fault = $this->fault('Recursive system.multicall forbidden', 605);                }            }            if (!$fault) {                try {                    $request = new Zend_XmlRpc_Request();                    $request->setMethod($method['methodName']);                    $request->setParams($method['params']);                    $response = $this->_handle($request);                    $responses[] = $response->getReturnValue();                } catch (Exception $e) {                    $fault = $this->fault($e);                }            }            if ($fault) {                $responses[] = array(                    'faultCode'   => $fault->getCode(),                    'faultString' => $fault->getMessage()                );            }        }        return $responses;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -