static function process() { // Set the method self::$METHOD = $_SERVER['REQUEST_METHOD']; // Get the request parts $request_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if (Kennel::getSetting('application', 'use_mod_rewrite')) { $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL)); } else { $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL . '/index.php')); } $action_string = str_replace(strstr($action_string, '?'), '', $action_string); $action_array = array_filter(explode('/', $action_string)); // Reasign action keys (to avoid empty entries due to double slashes) and convert to lowercase foreach ($action_array as $key => $part) { if ($part) { if (strpos($part, ':') === false) { self::$PARTS[] = input::clean($part); } else { $named_arg = explode(':', $part); self::$NAMED_ARGS[$named_arg[0]] = $named_arg[1]; } } } // Process any hooks if present if (is_array(self::$HOOKS) && count(self::$HOOKS > 0)) { foreach (self::$HOOKS as $hook) { self::$PARTS = call_user_func($hook, self::$PARTS); } } // Make the Resource String available to the API self::$RESOURCE = implode('/', self::$PARTS); // i18n URL redirection if (Kennel::getSetting('i18n', 'enabled') && Kennel::getSetting('i18n', 'redirect') && !router::$PREFIX) { header('location: ' . url(Request::$RESOURCE, i18n::getLang())); } // 0. Render the Home Page if no Request::PARTS are present if (count(self::$PARTS) == 0) { self::$CONTROLLER = 'Main'; self::$ACTION = 'index'; } // 1. First check: method in the main controller if (isset(self::$PARTS[0]) && method_exists('Main_controller', str_replace('-', '_', self::$PARTS[0]))) { self::$CONTROLLER = 'main'; self::$ACTION = str_replace('-', '_', self::$PARTS[0]); self::$ARGS = array_slice(self::$PARTS, 1); } // 2. Second check: user defined controller... if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/application/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) { self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0])); if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) { self::$ACTION = str_replace('-', '_', self::$PARTS[1]); self::$ARGS = array_slice(self::$PARTS, 2); } else { self::$ACTION = 'index'; self::$ARGS = array_slice(self::$PARTS, 1); } } // 3. Third check: module controller if (isset(self::$PARTS[0])) { if (!Kennel::$MODULES) { Kennel::fetchModules(); } foreach (Kennel::$MODULES as $module => $info) { if (is_file(Kennel::$ROOT_PATH . "/modules/{$module}/controllers/" . str_replace('-', '_', self::$PARTS[0]) . '.php')) { self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0])); if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) { self::$ACTION = str_replace('-', '_', self::$PARTS[1]); self::$ARGS = array_slice(self::$PARTS, 2); } else { self::$ACTION = 'index'; self::$ARGS = array_slice(self::$PARTS, 1); } } } } // 4. Forth check: system controller if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/system/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) { self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0])); if (isset(self::$PARTS[1])) { if (method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) { self::$ACTION = str_replace('-', '_', self::$PARTS[1]); self::$ARGS = array_slice(self::$PARTS, 2); } } else { self::$ACTION = 'index'; self::$ARGS = array_slice(self::$PARTS, 1); } } // 5. Fifth check: nothing found if (!self::$CONTROLLER) { self::$CONTROLLER = 'Main'; } if (!self::$ACTION) { self::$ACTION = 'notfound'; } if (self::$CONTROLLER == 'Main' && self::$ACTION == 'notfound') { self::$ARGS = self::$PARTS; } return Kennel::controllerAction(self::$CONTROLLER, self::$ACTION, self::$ARGS); }