public static function autoload ($class)// This loads the file {// Auto Load class // load a class // Detecting namespace Aliases if (!empty (self:: $namespaceAlias)) {// If you have namespaces $namespace = DirName ($class);// namespaces through the class name path if (Isset (self:: $namespaceAlias [$namespace]) {// If there is an alias, through the path to dirname $ Original = self:: $namespaceAlias [$namespace] . ' \ \ ' . basename ($class); //connection is called latest of original category if (Class_exists ($ Original) {// If this can save return class_alias ($original, $class, false);// just return the class_alias // If this true class_alias alias is present: then go to the corresponding 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 // get a compatible file path in any environment // file self::findfiles // win environment is strictly case-sensitive 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 } }// This function basically means that automatically loads the corresponding file class file /** * find File * @param $class * @return bool */ private static function findfile ($class ) {// Find Files if (!empty (self::$ map[$class]) {// If file exists class mappings // Class Library mapping return self:: $map [$class]; }// if class name mapping // Find PSR-4 $LOGICALPATHPSR 4 = STRTR ($class, ' \ \ ', ds) . EXT;// return to the first section of data $first = $class [0];// get Latest data if (self:: $PREFIXLENGTHSPSR 4[$first]) {// If set This pre-defined variable isset foreach (self:: $PREFIXLENGTHSPSR 4[$first] as $prefix => $length) {// loops if (0 === strpos ($class, $prefix)) {// Find File foreach (Self:: $PREFIXDIRSPSR 4[$prefix] as $dir) {// loop catalogue if (Is_file ($file = $dir . ds . substr ($LOGICALPATHPSR 4, $length ))) { return $file; }// if file exists return to } } } }// if file presence direct return // Find PSR-4 fallback dirs foreach (self:: $FALLBACKDIRSPSR 4 as $dir) {// if has fallback Dirs Psr4 Cycle Show if (Is_file ($file = $dir . DS . $logicalPathPsr 4)) { return $file; } } If you have this standard file return file // find psr-0 if (false !== $pos = strrpos ($class, ' \ \ ')) {// If here // namespaced class name $LOGICALPATHPSR 0 = substr ($LOGICALPATHPSR 4, 0, $pos + 1)      . STRTR (substr ($logicalPathPsr 4, $pos + 1), ' _ ', DS);// processing files } else { // PEAR-like class name $logicalPathPsr 0 = strtr ($class, ' _ ', ds) . EXT;// here get Another way } if (Isset (self:: $PREFIXESPSR 0[$first]) {// If contains this first is class inside First foreach ( Self:: $PREFIXESPSR 0[$first] as $prefix => $dirs) {// loop Here's dir if (0 === strpos ($class, $prefix) {// if starts with this prefix foreach ($dirs as $dir) {// loops Data if (Is_file ($ file = $dir . DS . $LOGICALPATHPSR 0)) { return $file; } } } } }// has such data in format, which returns, directly and , is circular // find PSR-0 fallback dirs foreach (self:: $FALLBACKDIRSPSR 0 as $dir) { if (Is_file ($file = $dir . ds . $logicalPathPsr 0)) { return $file; } }// If the file has Return self:: $map [$class] = false;// otherwise, return data }
This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1858861
[Li Jingshan php] every day tp5-20161204| Loader.php-2