Passed
Push — master ( c547da...5d2787 )
by 世昌
02:10 queued 15s
created

Request   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrlParameter() 0 5 2
A getParameter() 0 5 3
A getQueryParameter() 0 5 2
A setUrlParameter() 0 2 1
1
<?php
2
namespace suda\application;
3
4
use suda\component\request\Request as BaseRequest;
5
use suda\component\route\RequestInterface;
6
7
/**
8
 * 网页请求封装
9
 */
10
class Request extends BaseRequest implements RequestInterface
11
{
12
    protected $urlParameter;
13
14
    /**
15
     * 设置路由匹配值
16
     *
17
     * @param array $value
18
     * @return void
19
     */
20
    public function setUrlParameter(array $value) {
21
        $this->urlParameter = $value;
22
    }
23
24
    /**
25
     * 获取GET值
26
     *
27
     * @param string|null $name
28
     * @param mixed $default
29
     * @return mixed
30
     */
31
    public function getParameter(?string $name = null, $default = null) {
32
        if (is_null($name)) {
33
            return array_merge($this->queryParameter, $this->urlParameter);
34
        }
35
        return $this->urlParameter[$name] && $this->queryParameter[$name] ?? $default;
36
    }
37
38
    /**
39
     * 获取查询参数
40
     *
41
     * @param string|null $name
42
     * @param mixed $default
43
     * @return mixed
44
     */
45
    public function getQueryParameter(?string $name = null, $default = null) {
46
        if (is_null($name)) {
47
            return $this->queryParameter;
48
        }
49
        return $this->queryParameter[$name] ?? $default;
50
    }
51
52
    /**
53
     * 获取URL中的参数
54
     *
55
     * @param string|null $name
56
     * @param mixed $default
57
     * @return mixed
58
     */
59
    public function getUrlParameter(?string $name = null, $default = null) {
60
        if (is_null($name)) {
61
            return $this->urlParameter;
62
        }
63
        return $this->urlParameter[$name] ?? $default;
64
    }
65
}
66