Пример #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
 /**
  * Find matching route in XML route configuration and return modified request string 
  *
  * @param string $request
  * @return mixed
  * @deprecated
  */
 private final function xml_route($request)
 {
     $xml_routes = new XML\Parser();
     $xml_routes->load_from_file($this->routes_file);
     $routes = $xml_routes->getElementsByAttributeValue('method', Request::get_request_type());
     $found_route = null;
     foreach ($routes as $item) {
         if ($item->nodeType == XML_ELEMENT_NODE) {
             foreach ($item->childNodes as $attr) {
                 if ($attr->nodeType == XML_ELEMENT_NODE) {
                     if ($attr->tagName == "request") {
                         if ($item->getAttribute('method') == $_SERVER['REQUEST_METHOD']) {
                             $match_route = $item->cloneNode(true);
                             $controller = $match_route->getElementsByTagName('controller')->item(0)->nodeValue;
                             $action = $match_route->getElementsByTagName('action')->item(0)->nodeValue;
                             $match = str_ireplace('/', '\\/', $match_route->getElementsByTagName('request')->item(0)->nodeValue);
                             $match = '/^' . $match . '$/';
                             $replace = "/{$controller}/{$action}";
                             if ($match_route->getAttribute('args') == true) {
                                 $args_num = $match_route->getAttribute('argsnum');
                                 $number_args = !empty($args_num) ? $args_num : preg_match_all("/(\\(.*?\\))/", $match);
                                 for ($i = 1; $i <= $number_args; $i++) {
                                     $replace .= "/\$" . $i;
                                 }
                             }
                             if (preg_match($match, $request)) {
                                 $request = preg_replace($match, $replace, $request);
                                 $found_route = $item->cloneNode(true);
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         if ($found_route !== null) {
             break;
         }
     }
     return $request;
 }
Пример #3
0
     $view = $controller->index();
 } else {
     $args = explode("/", Request::get()['request']);
     array_shift($args);
     if (count($args) > 1) {
         $controller = $args[0];
         array_shift($args);
         $action = $args[0];
         array_shift($args);
     } else {
         $controller = $args[0];
         array_shift($args);
         $action = "index";
     }
     // Add post arguments to args array
     if (Request::get_request_type() != "GET") {
         $args = array_merge($args, Request::post());
     }
     if (!empty(Request::files())) {
         $args = array_merge($args, array("uploads" => Request::files()));
     }
     $maj_controller = ucfirst($controller) . 'Controller';
     print $maj_controller;
     if (class_exists('Apine\\Controllers\\System\\' . $maj_controller) && method_exists('Apine\\Controllers\\System\\' . $maj_controller, $action)) {
         $return = 'Apine\\Controllers\\System\\' . $maj_controller;
         $controller = new $return();
         $view = $controller->{$action}($args);
     } else {
         throw new GenericException('Not Found', 404);
     }
 }