标签:入口 自动 keyword hvm ... lookup line dcl class
1.入口文件:autoload.php
里面没什么东西,就是导入ComposerAutoloader主题文件,一般由一个复杂的名字,不过不用担心就是机器随机生成的一个码而已,就是普通的一个类,名字比较长了。
require_once __DIR__ . ‘/composer/autoload_real.php‘;
return ComposerAutoloaderInitd0a5721608b46fc86f3b980fb0cea37d::getLoader();
2.自动加载主题文件:ComposerAutoloaderInitd0a5721608b46fc86f3b980fb0cea37d
getLoader(){.....}
这个就是获得自动加载的主方法,这个有点像代加工厂、里面其实只是组装了下,实际的部件在别的类(后面会提到的ClassLoader类),接下来说说getLoader方法做了哪些代加工
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd0a5721608b46fc86f3b980fb0cea37d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd0a5721608b46fc86f3b980fb0cea37d::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInitd0a5721608b46fc86f3b980fb0cea37d::$prefixesPsr0;
}, null, ClassLoader::class);
$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);
}
spl_autoload_register(array($this, ‘loadClass‘), true, $prepend);
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, ‘.php‘);
// Search for Hack files if we are running on HHVM
if (false === $file && defined(‘HHVM_VERSION‘)) {
$file = $this->findFileWithExtension($class, ‘.hh‘);
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
标签:入口 自动 keyword hvm ... lookup line dcl class
原文地址:http://www.cnblogs.com/wangmy/p/6692970.html