public function testScalar() { //Arrange $_GET["foo"] = 5; //Act $php = \BTRAutoMap::Query(); //Assert $this->assertTrue($php->get->foo == 5); }
/** * Execute the route */ public function Execute() { $path = $this->GetQueryString(); if (!isset($this->routes["/"])) { return false; } if (defined("__BUTTERPHP_FILTER__") || defined("__BUTTERPHP_ALL__")) { $_GET = \BTRAutoFilter::Filter($_GET); $_POST = \BTRAutoFilter::Filter($_POST); } $p = !is_null($path) ? $path : '/'; $php = \BTRAutoMap::Query(); $php->router = $this; $php->HTTPCode = !isset($this->routes[$p]) || !isset($this->routes[$p . "/"]) ? 404 : 200; foreach ($this->routes as $key => $value) { $pattern = $key; if (!empty($this->parameterMap[$key])) { foreach ($this->parameterMap[$key] as $param) { $pattern .= "((?<" . $param . ">[^/]+)/)?"; } $result = "/" . addcslashes($pattern, "/") . "/"; $matches = array(); $matched = preg_match($result, $path, $matches); if ($matched === 1) { if (empty($php->get)) { $php->get = new \stdClass(); } foreach ($matches as $matchKey => $matchValue) { if (!is_numeric($matchKey)) { $php->get->{$matchKey} = $matchValue; } } return $this->routes[$key]($php); } } } if (isset($this->routes[$p])) { return $this->routes[$p]($php); } else { //return the base route if no correction is possible return $this->routes["/"]($php); } }