Router.php 704 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. class Router
  3. {
  4. private static $routes = array();
  5. public static function register(Action $route): void
  6. {
  7. self::$routes[$route->path] = $route;
  8. }
  9. public static function findRoute(string $path, string $method): Action
  10. {
  11. if (self::$routes[$path])
  12. {
  13. return self::$routes[$path];
  14. }
  15. else
  16. {
  17. return self::$routes["/404"]; // default route 404 handling goes here
  18. }
  19. }
  20. public static function scan(string $routesPath): void
  21. {
  22. $src = realpath(__DIR__ . "/../");
  23. foreach (glob($src . "/" . $routesPath) as $routeFile)
  24. {
  25. include $routeFile;
  26. }
  27. }
  28. }