• 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;
    }
  • 相关阅读:
    在Visual Studio中使用层关系图描述系统架构、技术栈
    在Visual Studio中使用活动图描述业务流程
    在Visual Studio中使用类图描述领域模型
    在Visual Studio中使用用例图描述参与者与用例的关系
    在Visual Studio中使用用例图描述系统与参与者间的关系
    并行编程中的取消任务、共享状态,等等
    等待所有或任意异步任务完成,以及异步任务完成时的处理方案
    使用IProgress实现异步编程的进程通知
    Task.FromResult应用场景举例
    Task.Delay方法的2个应用实例,单元测试等待,限时限次下载远程资源
  • 原文地址:https://www.cnblogs.com/8000cabbage/p/7508271.html
Copyright © 2020-2023  润新知