No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

40 líneas
852B

  1. <?php
  2. declare(strict_types=1);
  3. namespace Core;
  4. class Router
  5. {
  6. protected array $routes = [];
  7. public function get(string $path, callable|array|string $handler): Route
  8. {
  9. return $this->add('GET', $path, $handler);
  10. }
  11. public function post(string $path, callable|array|string $handler): Route
  12. {
  13. return $this->add('POST', $path, $handler);
  14. }
  15. public function add(string $method, string $path, callable|array|string $handler): Route
  16. {
  17. $route = new Route($method, $path, $handler);
  18. $this->routes[] = $route;
  19. return $route;
  20. }
  21. public function match(string $method, string $path): ?Route
  22. {
  23. foreach ($this->routes as $route) {
  24. if ($route->matches($method, $path)) {
  25. return $route;
  26. }
  27. }
  28. return null;
  29. }
  30. }

Powered by TurnKey Linux.