/** * Load Controller */ private function loadController() { $param = explode('/', $this->param()); // Set Deafult Controller if ('' === $param[0]) { $param[0] = $this->set['controller/default']; } $controller_param_temp = $param; $controller_name_temp = ucfirst($this->set['name']) . '\\Controller'; $controller_path_temp = $this->set['controller']; $controller_is_found = false; $controller_param = $controller_param_temp; $controller_name = $controller_name_temp; $controller_path = $controller_path_temp; // Search Controller while ($param) { $file_name = ucfirst($param[0]); if (file_exists("{$controller_path_temp}/{$file_name}Controller.php")) { array_shift($param); $controller_param_temp = $param; $controller_name_temp = "{$controller_name_temp}\\{$file_name}"; $controller_path_temp = "{$controller_path_temp}/{$file_name}"; $controller_is_found = true; $controller_param = $controller_param_temp; $controller_name = $controller_name_temp; $controller_path = $controller_path_temp; } elseif (file_exists("{$controller_path_temp}/{$file_name}")) { array_shift($param); $controller_param_temp = $param; $controller_name_temp = "{$controller_name_temp}\\{$file_name}"; $controller_path_temp = "{$controller_path_temp}/{$file_name}"; } else { break; } } // Response HTTP Status Code 404 if (!$controller_is_found) { http_response_code(404); return false; } // Require Controller require $controller_path . 'Controller.php'; // New Controller Instance $controller_name .= 'Controller'; $controller = new $controller_name(); if (method_exists($controller, $this->method() . 'Action')) { // Initialize Request Module Req::init(['method' => $this->method(), 'param' => $controller_param]); // Initialize Response Module Res::init(['path' => $this->set['view']]); // Call Function: up -> xxxAction -> down if (false !== $controller->up()) { $method = $this->method() . 'Action'; $controller->{$method}(); } $controller->down(); return true; } http_response_code(501); return false; }