| Total Complexity | 10 |
| Total Lines | 97 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Route |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * List of allow HTTP verbs |
||
| 12 | * |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | private $allows = []; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $name; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var callable|string |
||
| 24 | */ |
||
| 25 | private $action; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $path; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | private $parameters = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | private $wheres = []; |
||
| 41 | |||
| 42 | public function __construct(string $path, string $name, $action) |
||
| 43 | { |
||
| 44 | $this->name = $name; |
||
| 45 | $this->action = $action; |
||
| 46 | $this->path = $path; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Set a where rule to your route. |
||
| 51 | */ |
||
| 52 | public function where(array $expressions): Route |
||
| 53 | { |
||
| 54 | $this->wheres = array_merge($this->wheres, $expressions); |
||
| 55 | |||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string|array $allow |
||
| 61 | */ |
||
| 62 | public function allows($allows): Route |
||
| 63 | { |
||
| 64 | $this->allows = array_merge($this->allows, (array) $allows); |
||
| 65 | |||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | public function getPath(): string |
||
| 70 | { |
||
| 71 | return $this->path; |
||
| 72 | } |
||
| 73 | |||
| 74 | public function getName(): string |
||
| 75 | { |
||
| 76 | return $this->name; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return callable|string |
||
| 81 | */ |
||
| 82 | public function getAction() |
||
| 83 | { |
||
| 84 | return $this->action; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function getParameters(): array |
||
| 88 | { |
||
| 89 | return $this->parameters; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function setParameters(array $parameters): void |
||
| 93 | { |
||
| 94 | $this->parameters = array_merge($this->parameters, $parameters); |
||
| 95 | } |
||
| 96 | |||
| 97 | public function getWhere(): array |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getAllows(): array |
||
| 103 | { |
||
| 104 | return $this->allows; |
||
| 105 | } |
||
| 106 | } |
||
| 107 |