ThinkPHP6源码研读

ThinkPHP6源码研读,第1张

概述<?php//+----------------------------------------------------------------------//|ThinkPHP[WECANDOITJUSTTHINK]//+----------------------------------------------------------------------//|Copyright(c)2006-2019http:/hinkphp.cnAllri
<?PHP// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | copyright (c) 2006-2019 http://thinkPHP.cn All rights reserved.// +----------------------------------------------------------------------// | licensed ( http://www.apache.org/licenses/liCENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st <liu21st@gmail.com>// +----------------------------------------------------------------------// [ 应用入口文件 ]namespace think;require __DIR__ . '/../vendor/autoload.PHP';// 执行http应用并响应$http = (new App())->http;$response = $http->run();$response->send();$http->end($response);

第一步 引入

项目根目录/vendor/autoload.PHP

autoload文件如下

<?PHP// autoload.PHP @generated by Composerrequire_once __DIR__ . '/composer/autoload_real.PHP';return ComposerautoloaderInitb4bb23f5554b6a38d22fe61fc7fad9b3::getLoader();

由此可见,要引入autoload_real.PHP,然后执行 

 ComposerautoloaderInitb4bb23f5554b6a38d22fe61fc7fad9b3类下的getLoader方法
    /**     * @return \Composer\autoload\ClassLoader     */    public static function getLoader()    {        if (null !== self::$loader) {            return self::$loader;        }               require __DIR__ . '/platform_check.PHP';        spl_autoload_register(array('ComposerautoloaderInitb4bb23f5554b6a38d22fe61fc7fad9b3', 'loadClassLoader'), true, true);        self::$loader = $loader = new \Composer\autoload\ClassLoader();        spl_autoload_unregister(array('ComposerautoloaderInitb4bb23f5554b6a38d22fe61fc7fad9b3', 'loadClassLoader'));        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('Zend_loader_file_encoded') || !Zend_loader_file_encoded());        if ($useStaticLoader) {            require __DIR__ . '/autoload_static.PHP';            call_user_func(\Composer\autoload\ComposerStaticInitb4bb23f5554b6a38d22fe61fc7fad9b3::getinitializer($loader));        } else {            $map = require __DIR__ . '/autoload_namespaces.PHP';            foreach ($map as $namespace => $path) {                $loader->set($namespace, $path);            }            $map = require __DIR__ . '/autoload_psr4.PHP';            foreach ($map as $namespace => $path) {                $loader->setPsr4($namespace, $path);            }            $classMap = require __DIR__ . '/autoload_classmap.PHP';            if ($classMap) {                $loader->addClassMap($classMap);            }        }        $loader->register(true);        if ($useStaticLoader) {            $includefiles = Composer\autoload\ComposerStaticInitb4bb23f5554b6a38d22fe61fc7fad9b3::$files;        } else {            $includefiles = require __DIR__ . '/autoload_files.PHP';        }        foreach ($includefiles as $fileIDentifIEr => $file) {            composerRequireb4bb23f5554b6a38d22fe61fc7fad9b3($fileIDentifIEr, $file);        }        return $loader;    }

在getLoader方法 首先判断存在不存在$loader静态属性,如果不存在,则去引入当前目录下的(项目根目录/vendor/composer)platform_check.PHP 文件
platform_check.PHP主要是为了检测当前运行PHP的版本。

<?PHP// platform_check.PHP @generated by Composer$issues = array(); if (!(PHP_VERSION_ID >= 70205)) {    $issues[] = 'Your Composer dependencIEs require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.';}if ($issues) {    if (!headers_sent()) {        header('http/1.1 500 Internal Server Error');    }    if (!ini_get('display_errors')) {        if (PHP_SAPI === 'cli' || PHP_SAPI === 'PHPdbg') {            fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_Eol.PHP_Eol . implode(PHP_Eol, $issues) . PHP_Eol.PHP_Eol);        } elseif (!headers_sent()) {            echo 'Composer detected issues in your platform:' . PHP_Eol.PHP_Eol . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_Eol, $issues)) . PHP_Eol.PHP_Eol;        }    }    trigger_error(        'Composer detected issues in your platform: ' . implode(' ', $issues),        E_USER_ERROR    );}

如果检测通过,则去执行spl_autoload_register()自动加载函数

 

总结

以上是内存溢出为你收集整理的ThinkPHP6源码研读全部内容,希望文章能够帮你解决ThinkPHP6源码研读所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1167083.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存