Пример #1
0
 public function ParseRequest()
 {
     // Find the current request folder
     $requestRoot = $_SERVER['SCRIPT_NAME'];
     $this->RequestString = $_SERVER['REQUEST_URI'];
     $this->RequestUrl = $this->FixRequestUrl($this->RequestString);
     $routingEngine = new Routing($this->RoutesConfig);
     $requestData = $routingEngine->ParseUrl($requestRoot, $this->RequestUrl);
     if ($requestData != null) {
         $controllerName = $requestData['ControllerName'];
         $actionName = $requestData['ActionName'];
         $variables = $requestData['Variables'];
         if ($this->ApplicationCapitalizeControllerName()) {
             $controllerName = ucfirst($controllerName);
         }
         if ($this->ApplicationCapitalizeActionName()) {
             $actionName = ucfirst($actionName);
         }
         $handler = $this->CreateHandler($controllerName, $actionName, $requestData);
     } else {
         $handler = array('error' => 1, 'message' => 'Routing engine could not map request to a configured route');
     }
     // The controller or the action does not exists. If debugging is on, die and give an error, otherwise reroute to the notFound route
     if ($handler['error'] == 1) {
         $dieOnRoutingError = $this->DebugDieOnRoutingError();
         if ($dieOnRoutingError) {
             trigger_error($handler['message'], E_USER_ERROR);
         } else {
             $notFoundHandler = $this->CreateNotFoundHandler($requestData);
             // If the not found handler is not found or has en error, there is not much to do
             if ($notFoundHandler['error'] == 1) {
                 trigger_error('NotFoundHandler: ' . $notFoundHandler['message'], E_USER_ERROR);
             }
             $controller = $notFoundHandler['controller'];
             $actionName = $notFoundHandler['actionName'];
         }
     } else {
         $controller = $handler['controller'];
     }
     $this->UpdateNonces();
     $this->ParseData($controller);
     // Call the action
     $controller->BeforeAction();
     call_user_func_array(array($controller, $actionName), $variables);
     // Set data based on the call
     if (function_exists('http_response_code')) {
         http_response_code($controller->ReturnCode);
     }
     // 404 errors use the notFound route specified in the application config
     if ($controller->ReturnCode === 404) {
         $notFoundHandler = $this->CreateNotFoundHandler($requestData);
         if ($notFoundHandler['error'] == 1) {
             trigger_error('NotFoundHandler: ' . $notFoundHandler['message'], E_USER_ERROR);
         } else {
             $notFoundController = $notFoundHandler['controller'];
             $notFoundAction = $notFoundHandler['actionName'];
             $controller->BeforeAction();
             call_user_func_array(array($notFoundController, $notFoundAction), array());
         }
     }
     // Clean up
     $this->Database->Close();
 }