Passed
Push — master ( 4aed4d...8895e9 )
by Maxime
06:43
created

Route::setMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Piface\Router;
4
5
/**
6
 * Represent a register route.
7
 */
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
98
    {
99
        return $this->wheres;
100
    }
101
102
    public function getAllows(): array
103
    {
104
        return $this->allows;
105
    }
106
}
107