• 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;
    }
  • 相关阅读:
    Java面试题(01)
    HTML学习笔记16——尺寸的表示_px、%、em三种
    HTML学习笔记14——HTML 有语义的标签3_字符实体
    HTML13_有语义的标签2_a标签(超链接,锚点,伪类)
    HTML学习笔记12——HTML 有语义的标签1(h,p标签,img标签,列表,表格_制作课程表)
    HTML学习笔记11——CSS 初始化
    HTML学习笔记9——CSS精确控制背景图片位置——background-position
    HTML学习笔记8——CSS设置背景图片
    CSS控制文字的一些基本属性的使用
    HTML学习笔记5——盒模型(这里有棵圣诞树。)
  • 原文地址:https://www.cnblogs.com/8000cabbage/p/7508271.html
Copyright © 2020-2023  润新知