44namespace App \Route ;
55
66
7+ use App \Notification \MessageTypeEnum ;
8+ use App \Notification \StatusCodeEnum ;
9+ use App \Slack \SlackNotification ;
710use InvalidArgumentException ;
811use ReflectionException ;
912use ReflectionMethod ;
1013
11- class Router implements RouterInterface
14+ final class Router implements RouterInterface
1215{
13- private const NOT_FOUND_CODE = 204 ;
1416 private array $ routes = [];
1517
1618 public function dispatch (string $ uri , array $ params = []): void
1719 {
1820 if (key_exists ($ uri , $ this ->routes )) {
1921 $ uriContent = $ this ->routes [$ uri ];
2022 $ reflectedControllerMethod = self ::createReflectionMethod ($ uriContent );
21-
2223 $ reflectedControllerMethod ->invokeArgs (new $ uriContent ['namespace ' ], $ params );
2324 }
2425
25- throw new InvalidArgumentException ("' {$ uri }' is an unregistered route " , self :: NOT_FOUND_CODE );
26+ throw new InvalidArgumentException ("' {$ uri }' is an unregistered route " , StatusCodeEnum:: NOT_FOUND () );
2627 }
2728
2829 public function registry (string $ uri , string $ controller , string $ method ): void
@@ -38,7 +39,7 @@ private static function createReflectionMethod(array $uriContent): ReflectionMet
3839 try {
3940 return new ReflectionMethod ($ uriContent ['namespace ' ], $ uriContent ['method ' ]);
4041 } catch (ReflectionException $ exception ) {
41- print $ exception ->getMessage ();
42+ ( new SlackNotification ( $ exception ->getMessage (), MessageTypeEnum:: ERROR ()))-> notify ();
4243 }
4344 }
4445}
0 commit comments