Route::setArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the jade/jade package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jade\Routing;
13
14
class Route
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $name;
20
21
    /**
22
     * @var string
23
     */
24
    protected $pattern;
25
26
    /**
27
     * @var string|callable
28
     */
29
    protected $action;
30
31
    /**
32
     * @var array
33
     */
34
    protected $methods;
35
36
    /**
37
     * @var array
38
     */
39
    protected $arguments = [];
40
41
    public function __construct($name, $pattern, $action, $methods = [])
42
    {
43
        $this->name = $name;
44
        $this->pattern = $pattern;
45
        $this->action = $action;
46
        $this->methods = $methods;
47
    }
48
49
    /**
50
     * 返回路由唯一名称
51
     *
52
     * @return string
53
     */
54
    public function getName(): ?string
55
    {
56
        return $this->name;
57
    }
58
59
    /**
60
     * 设置唯一名称
61
     *
62
     * @param string $name
63
     */
64
    public function setName(string $name): void
65
    {
66
        $this->name = $name;
67
    }
68
69
    /**
70
     * 返回路由 pattern
71
     *
72
     * @return string
73
     */
74
    public function getPattern(): string
75
    {
76
        return $this->pattern;
77
    }
78
79
    /**
80
     * 设置路由 pattern
81
     *
82
     * @param string $pattern
83
     */
84
    public function setPattern(string $pattern): void
85
    {
86
        $this->pattern = $pattern;
87
    }
88
89
    /**
90
     * 获取路由动作
91
     *
92
     * @return callable|string
93
     */
94
    public function getAction()
95
    {
96
        return $this->action;
97
    }
98
99
    /**
100
     * 设置路由动作
101
     *
102
     * @param callable|string $action
103
     */
104
    public function setAction($action): void
105
    {
106
        $this->action = $action;
107
    }
108
109
    /**
110
     * 获取路由限制的请求
111
     *
112
     * @return array
113
     */
114
    public function getMethods(): array
115
    {
116
        return $this->methods;
117
    }
118
119
    /**
120
     * 设置路由限制请求
121
     *
122
     * @param array $methods
123
     */
124
    public function setMethods(array $methods): void
125
    {
126
        $this->methods = $methods;
127
    }
128
129
    /**
130
     * 获取参数
131
     *
132
     * @return array
133
     */
134
    public function getArguments(): array
135
    {
136
        return $this->arguments;
137
    }
138
139
    /**
140
     * 设置参数
141
     *
142
     * @param array $arguments
143
     */
144
    public function setArguments(array $arguments): void
145
    {
146
        $this->arguments = $arguments;
147
    }
148
149
    /**
150
     * 设置单个参数
151
     *
152
     * @param string $name
153
     * @param mixed $value
154
     */
155
    public function setArgument($name, $value)
156
    {
157
        $this->arguments[$name] = $value;
158
    }
159
160
    /**
161
     * 获取单个参数
162
     *
163
     * @param string $name
164
     * @param mixed $default
165
     * @return mixed
166
     */
167
    public function getArgument($name, $default = null)
168
    {
169
        return $this->arguments[$name] ?? $default;
170
    }
171
}