// Registration classmap public static function Addclassmap ($class, $map = ") {// if addClassMap class file mapping, support arrays, or key value two ways if (is_ Array ($class)) { self:: $map = array_merge (self:: $map, $class); } else { self:: $map [$class] = $map; } } // Register namespace public static function addnamespace ($namespace, $path = ") {// new namespace registration // Features: Support key value Arrays Assignment Methods if (Is_array ($ namespace) {// if array If it is an array foreach ($namespace as $prefix => $paths) {              SELF::ADDPSR4 ($prefix . ' \ \ ', rtrim ($paths, ds), true); } } else {// Selection Single stroke Outsourced             SELF::ADDPSR4 ($namespace . ' \ \ ', rtrim ($path, ds), true); } } // Add Ps0 space private static Function addpsr0 ($prefix, $paths, $prepend = false) {// add PS0 space, // If does not exist prefix inside // give the data to fallbackDirsPsr0 // prepend Representative: Is the configuration greater than the Convention, or the contract is greater than the configuration, this is a common technique, good, good job! if (! $prefix) {// If there is no corresponding namespace or prefix if ($prepend) {// The default is   FALSE&NBSP, and the incoming true normal call is to execute this self:: $FALLBACKDIRSPSR 0 = array_merge ( (Array) $paths, &nbsP; self:: $FALLBACKDIRSPSR 0 );// full use of array_merge For different locations coverage direction is not the same, resulting. } else { self:: $FALLBACKDIRSPSR 0 = array_merge ( self:: $FALLBACKDIRSPSR 0, (array) $paths ); } return;// returns directly does not perform down // same deep support }// if present first // configuration to corresponding prefix $first = $prefix [0];// If you have this first if (!isset (self:: $PREFIXESPSR 0[$first [$prefix])) {// If you do not have this self:: $PREFIXESPSR 0[$first] [$prefix] = (Array) $paths;// settings, and then return to return;// End } // Default Set merge if ($prepend) {// Coverage or Conventions &nbsP; self:: $PREFIXESPSR 0[$first] [$prefix] = array_merge ( (array) $paths, self:: $PREFIXESPSR 0[$first] [$prefix] ); } else { self:: $PREFIXESPSR 0[$first] [$prefix] = array_merge ( self:: $PREFIXESPSR 0[ $first [$prefix], (array) $paths ); } }// is a space to add // add PSR4 space   PRIVATE STATIC FUNCTION ADDPSR4 ($prefix, $paths, $prepend = False) {// same code if (!$ Prefix) { // Register directories for the root namespace. // Lao Liu Ah, this you have copied, I am also drunk, haha, if ($prepend) { self:: $fallbackDirsPsr 4 = array_merge ( (array) $paths, self::$ fallbackdirspsr4 ); } else { self:: $FALLBACKDIRSPSR 4 = array_merge ( self:: $FALLBACKDIRSPSR 4, (array) $paths ); } } elseif (!isset (self:: $PREFIXDIRSPSR 4[$prefIX])) {// registration If not set these // Register directories for a new namespace. $length = strlen ($prefix);// length if (' \ \ ' !== $prefix [$length - 1]) {// if trailer not this throw new \invalidargumentexception ("A non-empty psr-4 prefix must end with a namespace separator. "); } self:: $PREFIXLENGTHSPSR 4[$prefix [0]][$prefix] = $length; self:: $PREFIXDIRSPSR 4[$prefix] = (array) $paths; // same like ps0 } elseif ($prepend) {// in this word,they said prepend or append // prepend directories for an already registered namespace. self:: $PREFIXDIRSPSR 4[$prefix] = array_merge ( (array) $paths, self:: $PREFIXDIRSPSR 4[$prefix] ); } else { // append directories for an already registered namespace. self:: $PREFIXDIRSPSR 4[$prefix] = array_merge ( self:: $PREFIXDIRSPSR 4[$prefix], (array) $paths ); } } // Registering namespace Aliases public static function addnamespacealias ($namespace, $original = ") {// This English name feel when inappropriate Yang Ah, haha, should be register name space alias if (Is_array ($namespace)) { self:: $namespaceAlias = array_merge (self:: $namespaceAlias, $namespace); } else { self:: $namespaceAlias [$namespace] = $original; } } /** * Use this auto-load function * @param string $autoload */ // Registration automatic loading mechanism public static function register ($autoload = ") {// Focus! Focus! Focus! Focus! Focus! Focus! Focus! Focus! Focus! Focus! Focus! // important things to Say // registration system automatic loading spl_autoload_register ($autoload ?: ' think\\loader::autoload ', true, true); // doing system loading functions Auto-Registration // Auto Load file // features, that is, when used, the automatic loading, is better than the current full load, this is his propaganda on-demand loading! If there is no corresponding need pre-loaded things, the default is detect the file is correct, Direct use return include for // through class name, according to different standard do load, more internationalization, you progress // in fact, the core technology in this should be the path of Ps0 and Ps4 standard different standards. // implementation of class file loading under different standards This is key // registering namespace definitions self::addnamespace ([ ' Think ' => LIB_PATH . ' think ' . DS, ' behavior ' => LIB_PATH . ' behavior ' . DS, ' Traits ' => LIB_PATH . ' Traits ' . DS, ]);// If start namespace configuration // Load Class Library mapping file if (Is_file (runtime_path . ' Classmap ' . ext)) { self :: Addclassmap (__include_File (runtime_path . ' Classmap ' . ext)); }// Load class map // composer auto-load Support if (Is_dir (vendor_path . ' composer ')) { self::registercomposerloader (); }// Registration Various composerLoader // Auto Load Extend directory self:: $FALLBACKDIRSPSR 4[] = rtrim (EXTEND_PATH, DS);// load the corresponding directory }
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/1858899
[Li Jingshan php] every day tp5-20161205| Loader.php-3