Passed
Push — 8.0 ( d13e09...bf2321 )
by liu
13:01
created

UrlRuleItem   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 20
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;
18
use think\route\dispatch\Callback;
19
20
/**
21
 * 路由规则类
22
 */
23
class UrlRuleItem extends RuleItem
24
{
25
    /**
26
     * 检测路由(含路由匹配)
27
     * @access public
28
     * @param  Request      $request  请求对象
29
     * @param  string       $url      访问地址
30
     * @param  bool         $completeMatch   路由是否完全匹配
31
     * @return Dispatch|false
32
     */
33
    public function check(Request $request, string $url, bool $completeMatch = false)
34
    {
35
        if ($this->request->method() == 'OPTIONS') {
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist on think\route\UrlRuleItem. Did you maybe forget to declare it?
Loading history...
36
            // 自动响应options请求
37
            return new Callback($this->request, $this->group, function () {
0 ignored issues
show
Bug Best Practice introduced by
The property group does not exist on think\route\UrlRuleItem. Did you maybe forget to declare it?
Loading history...
38
                return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']);
39
            });
40
        }
41
42
        return $this->checkRule($request, $url, null, $completeMatch);
43
    }
44
45
}
46