protected function processStringRoute($route) { //Run some route cleaning operations. $route = str_replace('\\', '/', $route); //Convert backslashes to forward slashes //Remove a starting forward slash if (substr($route, 0, 1) == '/') { $route = substr($route, 1, strlen($route) - 1); } //Remove trailing forward slash if (substr($route, strlen($route) - 1, 1) == '/') { $route = substr($route, 0, strlen($route) - 1); } //End routing information on the first "." occurance if (($end = strpos($route, '.')) !== false) { $route = substr($route, 0, $end); } //Check to see if a script exists with that route. $scriptRoute = SCRIPT_ROOT . $route . '.php'; if (file_exists($scriptRoute)) { //Check for valid path information if (ctype_alnum(str_replace(array('/', '_', '-'), '', $route))) { $this->setScript($route)->setType(self::ROUTE_SCRIPT); } } else { //No Script found, routing to controller/action //Split the route into it's component elements. $splitRoute = explode('/', $route); $routeCount = count($splitRoute); //If the route only contains a controller add the index action if ($routeCount == 0) { array_push($splitRoute, 'index'); array_push($splitRoute, 'index'); } elseif ($routeCount == 1) { array_push($splitRoute, 'index'); } elseif ($routeCount >= 2) { //If the action is numeric, it is not the action. Insert the index action into the route. if (is_numeric($splitRoute[1])) { $shift = array_shift($splitRoute); array_unshift($splitRoute, $shift, 'index'); } } //Check the Controller value and Set a valid value $controller = array_shift($splitRoute); if (ctype_alnum(str_replace('-', '', $controller)) && ctype_alpha(substr($controller, 0, 1))) { $this->setController(Staple_Link::methodCase($controller)); } else { //Bad info in the route, error out. throw new Exception('Invalid Route', Staple_Error::PAGE_NOT_FOUND); } //Check the Action Value and Set a valid value $action = array_shift($splitRoute); if (ctype_alnum(str_replace('-', '', $action)) && ctype_alpha(substr($action, 0, 1))) { $this->setAction(Staple_Link::methodCase($action)); } else { //Bad info in the route, error out. throw new Exception('Invalid Route', Staple_Error::PAGE_NOT_FOUND); } $this->setParams($splitRoute)->setType(self::ROUTE_MVC); } }