/** * Loads a remote class or method and executes the function and returns * the result * * @param string $method Is the method to execute * @param mixed $param values for the method * @return mixed $response the result of executing the method * @throws Zend_Amf_Server_Exception */ protected function _dispatch($method, $params = null, $source = null) { if (!isset($this->_table[$method])) { // if source is null a method that was not defined was called. if ($source) { $classPath = array(); $path = explode('.', $source); $className = array_pop($path); $uriclasspath = implode('/', $path); // Take the user supplied directories and add the unique service path to the end. foreach ($this->_directories as $dir) { $classPath[] = $dir . $uriclasspath; } require_once 'Zend/Loader.php'; try { Zend_Loader::LoadClass($className, $classPath); } catch (Exception $e) { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Class "' . $className . '" does not exist'); } // Add the new loaded class to the server. $this->setClass($className); } else { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Method "' . $method . '" does not exist'); } } $info = $this->_table[$method]; $argv = $info->getInvokeArguments(); if (0 < count($argv)) { $params = array_merge($params, $argv); } if ($info instanceof Zend_Server_Reflection_Function) { $func = $info->getName(); $return = call_user_func_array($func, $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) { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName(), 621); } $return = $info->invokeArgs($object, $params); } } else { require_once 'Zend/Amf/Server/Exception.php'; throw new Zend_Amf_Server_Exception('Method missing implementation ' . get_class($info)); } return $return; }