示例#1
0
 /**
  * 
  * {@inheritDoc}
  * @see ApineRouterInterface::route()
  */
 public function route($request)
 {
     try {
         $args = explode("/", $request);
         array_shift($args);
         $controller = $args[0];
         array_shift($args);
         // Add post arguments to args array
         $args = array_merge($args, Request::get_request_params());
         if (self::check_route($request)) {
             $route = new Route($controller, strtolower(Request::get_request_type()), $args);
         }
         if (!isset($route)) {
             throw new GenericException("Route \"{$controller}\" not Found", 404);
         }
         return $route;
     } catch (Exception $e) {
         throw new GenericException($e->getMessage(), $e->getCode(), $e);
     }
 }
示例#2
0
 /**
  * 
  * {@inheritDoc}
  * @see ApineRouterInterface::route()
  */
 public final function route($request)
 {
     $route_found = false;
     $vanilla_route_found = self::check_route($request);
     if (!$vanilla_route_found && file_exists($this->routes_file)) {
         switch ($this->routes_type) {
             case APINE_ROUTES_JSON:
                 $file_request = $this->json_route($request);
                 break;
             case APINE_ROUTES_XML:
                 $file_request = $this->xml_route($request);
                 break;
             default:
                 $file_request = null;
         }
         if ($file_request !== $request) {
             $route_found = true;
             $request = $file_request;
         }
     }
     $args = explode("/", $request);
     array_shift($args);
     if (count($args) > 1) {
         $controller = $args[0];
         array_shift($args);
         $action = $args[0];
         array_shift($args);
     } else {
         if (count($args) > 0) {
             $controller = $args[0];
             array_shift($args);
             $action = "index";
         } else {
             $controller = null;
             $action = null;
         }
     }
     // Add post arguments to args array
     $args = array_merge($args, Request::get_request_params());
     try {
         if ($this->check_route($request)) {
             $route = new Route($controller, $action, $args);
         }
         if (!isset($route)) {
             if ($route_found) {
                 throw new GenericException("Reference Found but Action not Accessible for Route \"{$controller}\"", 410);
             } else {
                 throw new GenericException("Route \"{$controller}\" not Found", 404);
             }
         }
         return $route;
     } catch (Exception $e) {
         throw new GenericException($e->getMessage(), $e->getCode(), $e);
     }
 }