/** * ### Sets the formatted request uri * * Router constructor. */ public function __construct() { $request = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; $_SESSION['REQUEST_URI'] = $request; $this->uri = $this->formatURI($request); $this->routes = json_decode(file_get_contents(httpdir() . 'routes.json'), true); }
/** * ### Returns the uri for a named route * * @param $name * @return int|string */ function route($name) { $routes = json_decode(file_get_contents(httpdir() . 'routes.json'), true); foreach ($routes as $uri => $route) { if (array_key_exists('name', $route) && $route['name'] === $name) { return $uri; } } return '#'; }
/** * ### Gets the full path to the template directory * * @return string */ function viewdir() { return realpath(httpdir() . 'resources/views/') . '/'; }