RouteTrait.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Michel\Traits;
  3. use Michel\Route as BaseRoute;
  4. trait RouteTrait
  5. {
  6. /**
  7. * Creates a new GET route with the given name, path, and handler.
  8. *
  9. * @param string $name The name of the route.
  10. * @param string $path The path of the route.
  11. * @param mixed $handler The handler for the route.
  12. * @return BaseRoute The newly created GET route.
  13. */
  14. public static function get(string $name, string $path, $handler): BaseRoute
  15. {
  16. return new BaseRoute($name, $path, $handler);
  17. }
  18. /**
  19. * Creates a new POST route with the given name, path, and handler.
  20. *
  21. * @param string $name The name of the route.
  22. * @param string $path The path of the route.
  23. * @param mixed $handler The handler for the route.
  24. * @return BaseRoute The newly created POST route.
  25. */
  26. public static function post(string $name, string $path, $handler): BaseRoute
  27. {
  28. return new BaseRoute($name, $path, $handler, ['POST']);
  29. }
  30. /**
  31. * Creates a new PUT route with the given name, path, and handler.
  32. *
  33. * @param string $name The name of the route.
  34. * @param string $path The path of the route.
  35. * @param mixed $handler The handler for the route.
  36. * @return BaseRoute The newly created PUT route.
  37. */
  38. public static function put(string $name, string $path, $handler): BaseRoute
  39. {
  40. return new BaseRoute($name, $path, $handler, ['PUT']);
  41. }
  42. /**
  43. * Creates a new DELETE route with the given name, path, and handler.
  44. *
  45. * @param string $name The name of the route.
  46. * @param string $path The path of the route.
  47. * @param mixed $handler The handler for the route.
  48. * @return BaseRoute The newly created DELETE route.
  49. */
  50. public static function delete(string $name, string $path, $handler): BaseRoute
  51. {
  52. return new BaseRoute($name, $path, $handler, ['DELETE']);
  53. }
  54. }