public function getController() { if (isset(self::$_controller)) { // check if we already have a controller return self::$_controller; // return current controller } else { // else process controller and action request $_split = preg_split("/\\?/", self::$_request); // split request $_uri = $_split[0]; $_map = preg_split("/\\//", $_uri, 0, PREG_SPLIT_NO_EMPTY); // check if there's a matching custom rule if ($_match = self::matchCustomConfig(self::$_route_table, $_uri)) { self::$_controller = $_match["controller"]; self::$_action = $_match["action"]; if (isset($_match["class"])) { self::$_class = $_match["class"]; } return self::$_controller; // return controller name } else { if (!isset($_map[0])) { // check if this is index URI (e.g. http://sub.domain.tld/) if (!self::matchDefaultRoutes($_uri, $_map)) { // check if we'll have a match using our default route rules // @todo find a better error message especially on debug mode header("HTTP/1.1 404 Not Found"); echo 'Router Error: Controller "' . DEFAULT_CONTROLLER . '" Not Found.'; exit(0); } } else { // No, we are not index URI if (!isset($_map[1])) { // check that we don't have an action/method on URI (e.g. /controller/action-name) if (!self::matchDefaultRoutes($_uri, $_map)) { // check if we'll have a match using our default route rules // @todo find a better error message especially on debug mode header("HTTP/1.1 404 Not Found"); echo 'Router Error: Controller "' . $_map[0] . '" Not Found.'; exit; } } else { // we have an action/method (e.g. /controller/action-name) if (!self::matchDefaultRoutes($_uri, $_map)) { // check if we'll have a match using our default route rules // @todo find a better error message especially on debug mode header("HTTP/1.1 404 Not Found"); echo 'Router Error: Action "' . $_map[1] . '" Not Found.'; exit; } } } return self::$_controller; // return controller name } // end second if } // end first if }