Exemplo n.º 1
0
 /**
  * Handle an Ajax Request
  * @param Ajax_Request $request
  * @return Json_Response or Json_Exception if the invoked class or method
  *  is not found or not callable or if the invokation is not allowed or
  *  throws an exception
  */
 public function handle(Ajax_Request $request)
 {
     try {
         if (isset($this->register[$request->getClass()])) {
             if (in_array($request->getMethod(), $this->register[$request->getClass()]['methods']) || is_null($this->register[$request->getClass()]['methods'])) {
                 if (!$this->register[$request->getClass()]['object']->isMethodInvokationAllowed($request)) {
                     throw new Exception('Remote method invokation not allowed : ' . $request->__toString());
                 }
                 if (is_callable(array($this->register[$request->getClass()]['object'], $request->getMethod()))) {
                     $response = call_user_func(array($this->register[$request->getClass()]['object'], $request->getMethod()), $request);
                     return new Json_Response(array('class' => $request->getClass(), 'method' => $request->getMethod(), 'parameters' => $request->getParameters(), 'response' => $response));
                 } else {
                     throw new Exception("Method not callable {$request->getMethod()} in class {$request->getClass()}");
                 }
             } else {
                 throw new Exception("Method not found {$request->getMethod()} in class {$request->getClass()}");
             }
         } else {
             throw new Exception("Class not found {$request->getClass()}");
         }
     } catch (Exception $e) {
         return new Json_Exception($e);
     }
 }