zoukankan      html  css  js  c++  java
  • thinkphp6-4

    、ThinkRoute->dispatch()  路由

    public function dispatch(Request $request, $withRoute = null) { //设置传入的Request对象到当前对象的属性上 $this->request = $request; //同上 这个是设置host $this->host = $this->request->host(true); //执行Route init 方法 初始化 $this->init(); //判断的withRoute是否为真 if ($withRoute) { //执行传入过来的匿名函数,加载路由 $withRoute(); //官方注释的是检测url路由,我这里姑且认为是路由分发吧 //check返回的是think outeDispatch 路由调度基础类对象 $dispatch = $this->check(); } else { //调用think outedispatchUrl类 //将当前的url地址传入进去,进行默认的url解析 $dispatch = $this->url($this->path()); } //执行Dispatch对象中的init方法 //这里用于绑定控制器和方法以及路由后置操作,例如:中间件、绑定模型数据 $dispatch->init($this->app); //执行路由调度。并返回一个Response对象 return $this->app->middleware->pipeline('route') ->send($request) ->then(function () use ($dispatch) { return $dispatch->run(); }); }

    6、ThinkRoute->init()  初始化

    protected function init() { //合并默认配置以及读取到的route.php配置 $this->config = array_merge($this->config, $this->app->config->get('route')); //判断路由中间件是否存储,如果存在则调用middleware类中的import方法 //注册route中间件 if (!empty($this->config['middleware'])) { $this->app->middleware->import($this->config['middleware'], 'route'); } //是否延迟解析 $this->lazy($this->config['url_lazy_route']); //读取到的 是否合并路由配置项赋值到类变量mergeRuleRegex中 $this->mergeRuleRegex = $this->config['route_rule_merge']; //获取配置:是否删除url最后的斜线 $this->removeSlash = $this->config['remove_slash']; //是否去除url最后的斜线 $this->group->removeSlash($this->removeSlash); }

    7、ThinkRouteDispatch->init()

    1
    2
    3
    4
    5
    6
    public function init(App $app)
    {
        $this->app = $app;
        // 执行路由后置操作
        $this->doRouteAfter();
    }

    8、ThinkRouteDispatch->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);
    }
  • 相关阅读:
    如何将英文PDF文献翻译成中文
    基于颜色的R2V软件快速矢量化
    ArcGIS下如何提取研究区域
    ArcGIS 如何设置地图显示范围大小
    基于GIS的空间分析功能分析芝加哥小熊队和白袜队的球迷范围
    C#中的字段,常量,属性与方法
    ArcGIS中的连接和关联表
    使用docker搭建Samba共享目录
    Docker国内镜像源的切换
    pl/sql中的取模运算
  • 原文地址:https://www.cnblogs.com/huaobin/p/14910224.html
Copyright © 2011-2022 走看看