1 | <?php |
||
2 | |||
3 | namespace MinasRouter\Traits; |
||
4 | |||
5 | use MinasRouter\Router\RouteGroups; |
||
6 | |||
7 | trait RouterHelpers |
||
8 | { |
||
9 | protected abstract function getHttpCode(String $slug); |
||
10 | protected abstract function instanceof($object, $class); |
||
11 | |||
12 | /** |
||
13 | * Method responsible for removing the bars |
||
14 | * at the beginning and end of the route. |
||
15 | * |
||
16 | * @param string $uri |
||
17 | * |
||
18 | * @return string |
||
19 | */ |
||
20 | protected function fixRouterUri(String $uri): String |
||
21 | { |
||
22 | if (!preg_match("/^\//", $uri, $match)) { |
||
23 | $uri = "/{$uri}"; |
||
24 | } |
||
25 | |||
26 | if (preg_match("/\/$/", $uri, $match)) { |
||
27 | $uri = rtrim($uri, "/"); |
||
28 | } |
||
29 | |||
30 | return $uri; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Method responsible for throwing a new exception. |
||
35 | * |
||
36 | * @param string $httpCode |
||
37 | * @param string $exception |
||
38 | * @param string $message = "" |
||
39 | * @param string|array|null ...$sprints |
||
40 | */ |
||
41 | private function throwException(String $httpCode, String $exception, String $message = "", ...$sprints): \Exception |
||
42 | { |
||
43 | throw new $exception( |
||
44 | sprintf($message, ...$sprints), |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
45 | $this->getHttpCode($httpCode) |
||
46 | ); |
||
47 | } |
||
48 | } |
||
49 |