1 | <?php |
||
12 | class Route |
||
13 | { |
||
14 | private $name; |
||
15 | private $method = ['get']; |
||
16 | private $pattern = '/'; |
||
17 | private $handler; |
||
18 | private $scope = Jarvis::DEFAULT_SCOPE; |
||
19 | private $router; |
||
20 | |||
21 | public function __construct(string $name = null, Router $router) |
||
22 | { |
||
23 | $this->name = $name; |
||
24 | $this->router = $router; |
||
25 | } |
||
26 | |||
27 | public function name(): ?string |
||
1 ignored issue
–
show
|
|||
28 | { |
||
29 | return $this->name; |
||
30 | } |
||
31 | |||
32 | public function method(): array |
||
33 | { |
||
34 | return $this->method; |
||
35 | } |
||
36 | |||
37 | public function setMethod($method): Route |
||
38 | { |
||
39 | $this->method = array_map('strtolower', (array) $method); |
||
40 | |||
41 | return $this; |
||
42 | } |
||
43 | |||
44 | public function pattern(): string |
||
45 | { |
||
46 | return $this->pattern; |
||
47 | } |
||
48 | |||
49 | public function setPattern(string $pattern): Route |
||
50 | { |
||
51 | $this->pattern = $pattern; |
||
52 | |||
53 | return $this; |
||
54 | } |
||
55 | |||
56 | public function handler() |
||
57 | { |
||
58 | return $this->handler; |
||
59 | } |
||
60 | |||
61 | public function setHandler($handler): Route |
||
62 | { |
||
63 | $this->handler = $handler; |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | public function scope(): string |
||
69 | { |
||
70 | return $this->scope; |
||
71 | } |
||
72 | |||
73 | public function setScope(string $scope): Route |
||
74 | { |
||
75 | $this->scope = $scope; |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | public function end(): Router |
||
81 | { |
||
82 | return $this->router->addRoute($this); |
||
83 | } |
||
84 | } |
||
85 |