| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- class Router
- {
- private static $routes = array();
- public static function register(Action $route): void
- {
- self::$routes[$route->path] = $route;
- }
- public static function findRoute(string $path, string $method): Action
- {
- if (self::$routes[$path])
- {
- return self::$routes[$path];
- }
- else
- {
- return self::$routes["/404"]; // default route 404 handling goes here
- }
- }
- public static function scan(string $routesPath): void
- {
- $src = realpath(__DIR__ . "/../");
- foreach (glob($src . "/" . $routesPath) as $routeFile)
- {
- include $routeFile;
- }
- }
- }
|