thinkphp6-4
、\Think\Route->dispatch() 路由
6、\Think\Route->init() 初始化
7、Think\Route\Dispatch->init()
|
1
2
3
4
5
6
|
public function init(App $app){ $this->app = $app; // 执行路由后置操作 $this->doRouteAfter();} |
8、Think\Route\Dispatch->run()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
public function run(): Response{ //判断$this->rule路由规则是否为RuleItem类的实例 //判断当前请求方法,是不是OPTIONS以及 //判断当前路由规则是否为自动注册的OPTIONS路由 if ($this->rule instanceof RuleItem && $this->request->method() == 'OPTIONS' && $this->rule->isAutoOptions()) { //获取当前的路由列表 $rules = $this->rule->getRouter()->getRule($this->rule->getRule()); $allow = []; foreach ($rules as $item) { //这里是循环把所有路由全部转成大写 $allow[] = strtoupper($item->getMethod()); } //创建并返回一个Response对象,调用create静态方法 return Response::create('', 'html', 204)->header(['Allow' => implode(', ', $allow)]); } //如果上面的不匹配则调用当前Dispatch类中的exec方法 //实例化控制器以及方法 $data = $this->exec(); //最后动态的返回一个Response对象。xml、json等等 return $this->autoResponse($data);} |

浙公网安备 33010602011771号