Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Route | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
getMethods | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getArguments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOrigins | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php declare(strict_types=1); |
2 | /* |
3 | * This file is part of Aplus Framework Routing Library. |
4 | * |
5 | * (c) Natan Felles <natanfelles@gmail.com> |
6 | * |
7 | * For the full copyright and license information, please view the LICENSE |
8 | * file that was distributed with this source code. |
9 | */ |
10 | namespace Framework\Routing\Attributes; |
11 | |
12 | use Attribute; |
13 | |
14 | /** |
15 | * Class Route. |
16 | * |
17 | * @package routing |
18 | */ |
19 | #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
20 | class Route |
21 | { |
22 | /** |
23 | * @var array<int,string> |
24 | */ |
25 | protected array $methods; |
26 | protected string $path; |
27 | protected string $arguments; |
28 | protected ?string $name; |
29 | /** |
30 | * @var array<string> |
31 | */ |
32 | protected array $origins; |
33 | |
34 | /** |
35 | * Route constructor. |
36 | * |
37 | * @param array<int,string>|string $methods The Route HTTP Methods |
38 | * @param string $path The Route path |
39 | * @param string $arguments The Route action arguments |
40 | * @param string|null $name The Route name |
41 | * @param array<string>|string $origins The Route origins |
42 | */ |
43 | public function __construct( |
44 | array | string $methods, |
45 | string $path, |
46 | string $arguments = '*', |
47 | string $name = null, |
48 | array | string $origins = [], |
49 | ) { |
50 | $methods = (array) $methods; |
51 | foreach ($methods as &$method) { |
52 | $method = \strtoupper($method); |
53 | } |
54 | unset($method); |
55 | $this->methods = $methods; |
56 | $this->path = $path; |
57 | $this->arguments = $arguments; |
58 | $this->name = $name; |
59 | $this->origins = (array) $origins; |
60 | } |
61 | |
62 | /** |
63 | * @return array<int,string> |
64 | */ |
65 | public function getMethods() : array |
66 | { |
67 | return $this->methods; |
68 | } |
69 | |
70 | /** |
71 | * @return string |
72 | */ |
73 | public function getPath() : string |
74 | { |
75 | return $this->path; |
76 | } |
77 | |
78 | /** |
79 | * @return string |
80 | */ |
81 | public function getArguments() : string |
82 | { |
83 | return $this->arguments; |
84 | } |
85 | |
86 | /** |
87 | * @return string|null |
88 | */ |
89 | public function getName() : ?string |
90 | { |
91 | return $this->name; |
92 | } |
93 | |
94 | /** |
95 | * @return array<string> |
96 | */ |
97 | public function getOrigins() : array |
98 | { |
99 | return $this->origins; |
100 | } |
101 | } |