Пример #1
0
 public function dispatch($c, $action)
 {
     if (!$c instanceof DF_Web) {
         throw new DF_Error_InvalidArgumentException('c', $c, 'DF_Web');
     }
     if (!$action instanceof DF_Web_Action) {
         throw new DF_Error_InvalidArgumentException('action', $action, 'DF_Web_Action');
     }
     $ctrl_name = $action->get_controller();
     $method = $action->get_method();
     $arguments = $action->get_arguments();
     $req = $c->request;
     $verb = $req->get_method();
     $verb = strtoupper($verb);
     $rest_method = $method . "_" . $verb;
     $controller = $c->controller($ctrl_name);
     # Prepend the context object to the argumentlist
     if ($arguments == NULL) {
         $arguments = array();
     }
     array_unshift($arguments, $c);
     if (!method_exists($controller, $rest_method)) {
         $c->response->status(405);
         #Method not allowed TODO check that it is 405 or other?
         $argstr = DF_Web_Utils_Arguments::flatten_arguments_list($arguments);
         self::$LOGGER->info("Action {$ctrl_name}->{$method} does not handle {$verb}");
         #throw new DF_Web_Detach_Exception($action, "Method not allowed: $verb");
         #throw new DF_Web_Exception("Method not allowed: $verb");
         return false;
     }
     try {
         $ret = call_user_func_array(array($controller, $rest_method), $arguments);
         return $ret;
     } catch (DF_Web_Detach_Exception $ex) {
         // Rethrow the exception to continue breaking the chain
         throw $ex;
     } catch (DF_Web_Exception $ex) {
         $c->add_error($ex);
         self::$LOGGER->error("Fatal exception: " . $ex->getMessage());
     } catch (Exception $ex) {
         $c->add_error($ex);
         self::$LOGGER->error("Fatal exception, breaking off chain: " . $ex->getMessage());
         throw new DF_Web_Detach_Exception($this, "Got an error we cannot handle");
     }
     return false;
 }
Пример #2
0
 public function toString()
 {
     $args = "";
     if ($this->arguments) {
         $args = DF_Web_Utils_Arguments::flatten_arguments_list($this->arguments);
     }
     $ctrl = $this->controller;
     $method = $this->method;
     return "{$ctrl}->{$method}({$args})";
 }