[李景山php]每天TP5-20161204|Loader.php-2
来源:互联网 发布:常用推荐算法 编辑:程序博客网 时间:2024/06/05 16:42
public static function autoload($class)// 这个就加载文件 {// 自动加载 类 // 加载一个class // 检测命名空间别名 if (!empty(self::$namespaceAlias)) {// 如果有命名空间 $namespace = dirname($class);// 通过类名 的路径 来的 命名空间 if (isset(self::$namespaceAlias[$namespace])) {// 如果有别名, 通过路径来 dirname $original = self::$namespaceAlias[$namespace] . '\\' . basename($class); //连接称为 最新的 的 original 类的 if (class_exists($original)) {// 如果这个可以 存 return class_alias($original, $class, false);// just return the class_alias // 如果存在这个 真实的 class_alias 别名: 然后 进入到对应到的 class } } }// if this empty and this namespaceAlias also been said and this class has, //and return this class alias // else if ($file = self::findFile($class)) {// get file from the class name // 获取一个 在任何环境下 都能够兼容的 文件路径// file self::findFiles // Win环境严格区分大小写 if (IS_WIN && pathinfo($file, PATHINFO_FILENAME) != pathinfo(realpath($file), PATHINFO_FILENAME)) { return false; }// if IS_WIN in the this is a good type to make program so strong __include_file($file);// use a function to wrap a nomarl type return true;// then return true } }// 这个函数的意思,基本上就是 自动加载对应的文件 类文件 /** * 查找文件 * @param $class * @return bool */ private static function findFile($class) {// 查找文件 if (!empty(self::$map[$class])) {// 如果 文件存在 类映射 // 类库映射 return self::$map[$class]; }// 如果类名 映射 // 查找 PSR-4 $logicalPathPsr4 = strtr($class, '\\', DS) . EXT;// 返回第一节数据 $first = $class[0];// 获取 最新的数据 if (isset(self::$prefixLengthsPsr4[$first])) {// 如果设置了 这个 预定义变量 foreach (self::$prefixLengthsPsr4[$first] as $prefix => $length) {// 循环 if (0 === strpos($class, $prefix)) {// 找到文件 foreach (self::$prefixDirsPsr4[$prefix] as $dir) {// loop 目录 if (is_file($file = $dir . DS . substr($logicalPathPsr4, $length))) { return $file; }// 如果 文件 存在 就返回 } } } }// 如果 文件 存在 直接返回 // 查找 PSR-4 fallback dirs foreach (self::$fallbackDirsPsr4 as $dir) {// 如果 有 fallback Dirs Psr4 循环展示 if (is_file($file = $dir . DS . $logicalPathPsr4)) { return $file; } }// 如果有这个标准下 的 文件 返回文件 // 查找 PSR-0 if (false !== $pos = strrpos($class, '\\')) {// 如果这里 // namespaced class name $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) . strtr(substr($logicalPathPsr4, $pos + 1), '_', DS);// 处理文件 } else { // PEAR-like class name $logicalPathPsr0 = strtr($class, '_', DS) . EXT;// 这里 获取 另外一种方式 } if (isset(self::$prefixesPsr0[$first])) {// 如果 含这个 first 就是 class 里面的 第一个 foreach (self::$prefixesPsr0[$first] as $prefix => $dirs) {// 循环 这里的 dir if (0 === strpos($class, $prefix)) {// 如果 开始就是 这个 prefix foreach ($dirs as $dir) {// 循环 数据 if (is_file($file = $dir . DS . $logicalPathPsr0)) { return $file; } } } } }// 有这样 格式的 数据,直接返回, 而且,是循环的 // 查找 PSR-0 fallback dirs foreach (self::$fallbackDirsPsr0 as $dir) { if (is_file($file = $dir . DS . $logicalPathPsr0)) { return $file; } }// 如果文件有 return self::$map[$class] = false;// 否则, 返回数据 }
0 0
- [李景山php]每天TP5-20161204|Loader.php-2
- [李景山php]每天TP5-20161208|Loader.php
- [李景山php]每天TP5-20161203|Loader.php-1
- [李景山php]每天TP5-20161205|Loader.php-3
- [李景山php]每天TP5-20161206|Loader.php-4
- [李景山php]每天TP5-20161207|Loader.php-5
- [李景山php]每天TP5-20161212|App.php-2
- [李景山php]每天TP5-20161217|thinkphp5-helper.php-2
- [李景山php]每天TP5-20161225|thinkphp5-Console.php-2
- [李景山php]每天TP5-20170105|thinkphp5-File.php-2
- [李景山php]每天TP5-20170109|thinkphp5-Model.php-2
- [李景山php]每天TP5-20170117|thinkphp5-Url.php-2
- [李景山php]每天TP5-20170120|thinkphp5-Process.php-2
- [李景山php]每天TP5-20170130|thinkphp5-Request.php-2
- [李景山php]每天TP5-20170206|thinkphp5-Route.php-2
- [李景山php]每天TP5-20161202|base.php
- [李景山php]每天TP5-20161209|Error.php
- [李景山php]每天TP5-20161210|Config.php
- 如何解决“access violation at address”错误
- 2016年10月5日
- 字符串反转
- 值传递和引用传递,ref的作用,序列化和反序列化
- 【JZOJ 4810】【NOIP2016提高组 五校联考1】道路规划
- [李景山php]每天TP5-20161204|Loader.php-2
- Git上传代码到github
- C语言笔记(《C与指针》)
- Android使用post方式上传图片到服务器的方法
- Android基础之内存溢出
- 迷宫问题
- windows7下的PHP+apache+mysql+eclipse for php 开发环境搭建
- java单链表的基本操作
- 高中OJ3046. 【NOIP2012模拟10.23】游戏