TP5源码解读

框架流程:
    1.入口文件 index.php->加载基础文件 base.php->载入Loader类Loader.php
    2.注册自动加载Loader::register()
       Loader::register()主要实现两个功能:
        1).注册系统自动加载
        2).Composer自动加载支持

          (1)get_declared_classes  返回由当前脚本中已定义类的名字组成的数组。(当前文件类的集合)

        register函数主要处理四个数组属性:

          1. prefixLengthsPsr4

          2. prefixDirsPsr4

          3. fallbackDirsPsr4

          4. classMap

       self::addAutoLoadDir() 自定义加载类文件 如:在tp5下创建一个目录a/ali/send.php文件 使用self::addAutoLoadDir($rootPath,"a") 在控制下即可使用命名空间调用相对应的类,类似于extend

    3.composer类库安装
      直接复制到vendor/topthink目下,配置vendor/composer/autoload_static.php
      如think-helper类库
      public static $prefixLengthsPsr4 = array (
        't' =>
        array (
          'think\\composer\\' => 15,
          'think\\helper\\' => 13,
        ),
        'a' =>
          array (
            'app\\' => 4,
          ),
        );

      public static $prefixDirsPsr4 = array (
        'think\\composer\\' =>
        array (
          0 => __DIR__ . '/..' . '/topthink/think-installer/src',
        ),
      'think\\helper\\' =>
        array (
          0 => __DIR__ . '/..' . '/topthink/think-helper/src',
      ),
      'app\\' =>
      array (
        0 => __DIR__ . '/../..' . '/application',
      ),
    );

posted @ 2020-08-24 16:35  爱搬砖的小码农  阅读(487)  评论(0编辑  收藏  举报