parseUrl(); $controllerPath = __DIR__ . '/../app/controllers/'; // Controller Check (Case-insensitive) if (isset($url[0])) { $candidate = ucfirst(strtolower($url[0])) . 'Controller'; if (file_exists($controllerPath . $candidate . '.php')) { $this->controller = $candidate; unset($url[0]); } } require_once $controllerPath . $this->controller . '.php'; $this->controller = new $this->controller; // Method Check (Case-insensitive) if (isset($url[1])) { $candidateMethod = $url[1]; foreach (get_class_methods($this->controller) as $methodName) { if (strcasecmp($methodName, $candidateMethod) === 0 && strpos($methodName, '_') !== 0) { $this->method = $methodName; unset($url[1]); break; } } } // Params & Execution $this->params = $url ? array_values($url) : []; call_user_func_array([$this->controller, $this->method], $this->params); } // URL Parser private function parseUrl() { if (isset($_GET['url'])) { return explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL)); } return []; } }