/** * Loops through the defined lookup patterns until one matches * Any url variables that are explicitly set are ignored, this only works on the url portion * * @return void **/ public static function perform_mappings() { if (!self::$params) { self::$params = $_GET; } self::detect_maintenance(); //before mappings get the format if (!self::$params["format"] && preg_match("/(.*)\\.(.*)/", self::$params["route"], $matches)) { self::$params["format"] = $matches[2]; self::$params["route"] = $matches[1]; } //before mappings build a route array if (!self::$params["route_array"]) { self::$params["route_array"] = explode("/", self::$params["route"]); } foreach (self::$mappings as $map) { $left = $map[0]; $right = self::$params["route"]; if (substr($right, -1) == "/") { $right = substr($right, 0, -1); } //take off the first slash if it's there $left = preg_replace("/:([A-Za-z0-9\\-_]*\\*)/", "([A-Za-z0-9.\\-/_]*)", $left); $left = preg_replace("/:([A-Za-z0-9\\-_]*)/", "([A-Za-z0-9.\\-_]*)", $left); $left = str_replace("/", "\\/", $left); if ($left === $right && !strpos($left, ":")) { $mapped_route = $map[1]; } elseif (preg_match("/" . $left . "/", $right, $matches)) { if (!self::$params["controller"] && !$map[1]["controller"]) { self::route_controller(); break; } $mappings = split("/", $map[0]); array_shift($matches); while (count($mappings)) { if ($mappings[0] == $matches[0]) { // exact text mappings array_shift($matches); } elseif (substr($mappings[0], 0, 1) == ":" && substr($mappings[0], -1) == "*") { // *-based variable mappings to allow any number of variables $mapped_route[substr($mappings[0], 1, -1)] = explode("/", $matches[0]); } elseif (substr($mappings[0], 0, 1) == ":") { // variable-based mappings $mapped_route[substr($mappings[0], 1)] = $matches[0]; array_shift($matches); } array_shift($mappings); } $mapped_route = array_merge($mapped_route, (array) $map[1]); } // Map against named parameters in options array if ($mapped_route) { foreach ($mapped_route as $k => $val) { self::$params[$k] = $val; } break; } } self::force_defaults(); }
public function setUp() { $_POST = array(); $_GET = array(); WaxUrl::$params = false; Request::$params = false; }
function __construct($message, $code = "Page cannot be found", $status = "404") { if ($location = self::$redirect_on_error) { $this->error_heading = $code; $this->error_message = $this->format_trace($this); $this->error_site = str_ireplace("www.", '', $_SERVER['HTTP_HOST']); $this->error_site = substr($this->error_site, 0, strpos($this->error_site, '.')); $this->error_site_name = ucwords(Inflections::humanize($this->error_site)); $this->simple_routing_error_log(); if (!self::$double_redirect) { self::$double_redirect = true; header("HTTP/1.1 404 Not Found", 1, 404); if (is_readable(PUBLIC_DIR . ltrim($location, "/"))) { $content = file_get_contents(PUBLIC_DIR . ltrim($location, "/")); foreach (self::$replacements as $value => $replace) { $content = str_ireplace($replace, $this->{$value}, $content); } ob_end_clean(); echo $content; exit; } $_GET["route"] = $location; WaxUrl::$params = false; WaxUrl::perform_mappings(); $delegate = Inflections::slashcamelize(WaxUrl::get("controller"), true) . "Controller"; $delegate_controller = new $delegate(); $delegate_controller->execute_request(); exit; } else { WaxLog::log("error", "[Routing] Double redirect error"); $code = "Application Error"; $message = "A Page not found error was triggered and you have not set up a page to handle it"; } } parent::__construct($message, $code); }
public function setUp() { WaxUrl::$params = false; }