对composer自动加载的认识
                                                                
                18-02-05 15:21
                字数 973
                阅读 3004
                                已编辑
                                            
            通过composer下载的第三方扩展,会自动有一个vendor目录和一个autoload.php,vendor目录中包含composer目录,目录结构如下

在使用过程中首先应该在如自动加载脚本
//autoloaderwhenusingComposer
require('D:/www/xhl/phpbarcode/vendor/autoload.php');
//autoload.php脚本中会自动载入autoload_real.php,在其中载入composer\autoload_static.php;
//在autoload_static.php中
publicstaticfunctiongetInitializer(ClassLoader$loader)
{
return\Closure::bind(function()use($loader){
$loader->prefixLengthsPsr4=ComposerStaticInit713d85be4d0a0ba294ebd5a1837c9432::$prefixLengthsPsr4;
$loader->prefixDirsPsr4=ComposerStaticInit713d85be4d0a0ba294ebd5a1837c9432::$prefixDirsPsr4;
},null,ClassLoader::class);
}
通过闭包函数为$loader即composer\ClassLoader.php对象赋予属性并注册成自动加载函数
spl_autoload_register(array($this,'loadClass'),true,$prepend);
大部分通过findFileWithExtension找到对应的自动加载类;
$this->prefixLengths
Psr4提供了一个快速查找的分组对应的命名空间
$prefixLengths
Psr4中的长度决定截取的类名,其中的索引值大小写敏感
$length=$this->prefixLengthsPsr4[$first][$search];
if(file_exists($file=$dir.DIRECTORY_SEPARATOR.substr($logicalPathPsr4,$length))){
return$file;
}            0人点赞>
                    
                0 条评论
            
            
                排序方式
                时间
                投票
            
        快来抢占一楼吧
    请登录后发表评论
        
        相关推荐
        
    文章归档
    
最新文章
        最受欢迎
    20-01-06 10:49
                    19-12-18 13:52
                    19-12-08 13:06
                    19-12-06 18:19
                    19-11-20 19:17
                    6 评论
                    3 评论
                    2 评论
                    2 评论