Passed
Push — 8.0 ( cd7e8a...0aac54 )
by liu
11:57 queued 09:21
created

UrlRuleItem   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 20
ccs 0
cts 6
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 10 2
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2023 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\route;
14
15
use think\Request;
16
use think\Response;
17
use think\route\dispatch\Callback;
18
19
/**
20
 * 路由规则类
21
 */
22
class UrlRuleItem extends RuleItem
23
{
24
    /**
25
     * 检测路由(含路由匹配)
26
     * @access public
27
     * @param  Request      $request  请求对象
28
     * @param  string       $url      访问地址
29
     * @param  bool         $completeMatch   路由是否完全匹配
30
     * @return Dispatch|false
31
     */
32
    public function check(Request $request, string $url, bool $completeMatch = false)
33
    {
34
        if ($request->method() == 'OPTIONS') {
35
            // 自动响应options请求
36
            return new Callback($request, $this->parent, function () {
37
                return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']);
38
            });
39
        }
40
41
        return $this->checkRule($request, $url, null, $completeMatch);
42
    }
43
44
}
45