zoukankan      html  css  js  c++  java
  • Thinkphp5.1源码阅读

    主要流程

     

    1 publicindex.php

    require __DIR__ . '/../thinkphp/start.php';

    2 hinkphpstart.php

    require __DIR__ . '/base.php';
    // 执行应用并响应
    Container::get('app', [defined('APP_PATH') ? APP_PATH : ''])
        ->run()
        ->send();

      2.1 hinkphpase.php

    require __DIR__ . '/library/think/Loader.php';
    // 注册自动加载
    Loader::register();
    // 注册核心类到容器
    Container::getInstance()->bind([
        'app'                   => App::class, //App::class ≈ string(9) "thinkApp"
    //...
        'view'                  => View::class,
    //...
    ]);

    3 hinkphplibrary hinkApp.php

    
    
    public function run()
    {
    // 初始化应用
    $this->initialize(); //主要加载配置,助手函数
    // 执行调度
    $data = $dispatch->run(); //$dispatch = object(think outedispatchUrl)
    //...
    $response = Response::create(); // hinkphplibrary hinkResponse.php
    //...
    return $response;

      3.1 thinkphplibrary hink outedispatchUrl.php

    public function run()
    {
        // 解析默认的URL规则
        $url    = str_replace($this->param['depr'], '|', $this->dispatch);
        $result = $this->parseUrl($url);
        return (new Module($result))->run();
    }

          3.1.1 thinkphplibrary hink outedispatchModule.php

    public function run()
    {
    // 实例化控制器
        $instance = $this->app->controller( //thinkphplibrary	hinkApp.php
    //...
      $call = [$instance, $action]; //$instance = object(appusercontrollerHome)
    //...
      return Container::getInstance()->invokeMethod($call, $vars);

        3.2  hinkphplibrary hinkResponse.php

    public static function create($data = '', $type = '', $code = 200, array $header = [], $options = [])
        {
         //...
    if (class_exists($class)) { return new $class($data, $code, $header, $options); } else { return new static($data, $code, $header, $options); } }

      4

    //发送数据到客户端
    public function send()
        {
    //...
    echo $data;

    控制器中 $this->fetch()

    thinkphplibrary hinkController.php

    public function __construct()
        {
            $this->request = Container::get('request');
            $this->app     = Container::get('app');
            $this->view    = Container::get('view')->init(
                $this->app['config']->pull('template'),
                $this->app['config']->get('view_replace_str')
            );
    protected function fetch($template = '', $vars = [], $replace = [], $config = [])
        {
            return $this->view->fetch($template, $vars, $replace, $config);
        }

    thinkphplibrary hinkView.php

    public function init($engine = [], $replace = [])
        {
            // 初始化模板引擎
            $this->engine($engine); 
    public function engine($options = [])
    {
      
    $type = !empty($options['type']) ? $options['type'] : 'Think';   $class = false !== strpos($type, '\') ? $type : '\think\view\driver\' . ucfirst($type);
      $this->engine = new $class($options); //$this->engine = thinkphplibrary hinkviewdriverThink.php
      return $this;
    }
  • 相关阅读:
    Django关于StreamingHttpResponse与FileResponse响应文件或视频的下载请求
    APScheduler可能遇到的问题
    django中model聚合使用
    Java 递归判断迷宫问题是否有路
    direct path read/write (直接路径读/写)
    DRM 简介
    SQL Server2008表名中含“.”号处理方法
    Java学习之:JDK动态代理与CGLIB动态代理
    强大易用!新一代爬虫利器 Playwright
    为什么cudaMalloc()参数是二级指针
  • 原文地址:https://www.cnblogs.com/8000cabbage/p/7508271.html
Copyright © 2011-2022 走看看