addRoute($name, $path, $args[1], $filter); } } // Initialisation function public static function init($basePath = '/') { // Set base path self::setBasePath($basePath); // Create router self::$router = new RouteCollector; } // Set base path public static function setBasePath($basePath) { self::$basePath = $basePath; } // Parse the url private static function parseUrl($url) { return parse_url(str_replace(self::$basePath, '', $url), PHP_URL_PATH); } // Handle requests public static function handle($method, $url) { // Check if the dispatcher is defined if (self::$dispatcher === null) { self::$dispatcher = new Dispatcher(self::$router->getData()); } // Parse url $url = self::parseUrl($url); // Handle the request return self::$dispatcher->dispatch($method, $url); } }