自动加载

这里，我们之所以在未找到类时没有抛出异常是为了开发人员自动加载或者其他扩展类库有机会进行处理

@param string $className 等待加载的类名
772055
public function load($className) {
        if (class_exists($className, FALSE) || interface_exists($className, FALSE)) {
            return;
        }

        foreach ($this->dirs as $dir) {
            if ($this->loadClass($this->basePath . DIRECTORY_SEPARATOR . $dir, $className)) {
                return;
            }
    	}
    }
906515
public function loadClass($className)
    {
        $origClassName = str_replace('-', '', $className);

        /**/$this->app->pr->start('pathfinder/loadClass ');

        /**/$this->app->pr->next('pathfinder/loadClass/convertpath ');
        $className = ltrim($className, '\\');
        $nsPath = '';
        $namespace = '';
        if ($lastNsPos = strripos($className, '\\')) {
            $namespace = substr($className, 0, $lastNsPos);
            $className = substr($className, $lastNsPos + 1);
            $nsPath = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
        }
        $classPath = str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';

        /**/$this->app->pr->next('pathfinder/loadClass/locate ');
        try {
            if ($namespace) {
                if (strpos($className, 'page_') === 0) {
                    $path = $this->app->locatePath(
                        'addons',
                        $nsPath.DIRECTORY_SEPARATOR.$classPath
                    );
                } else {
                    $path = $this->app->locatePath(
                        'addons',
                        $nsPath.DIRECTORY_SEPARATOR
                        .'lib'.DIRECTORY_SEPARATOR.$classPath
                    );
                }
            } else {
                if (strpos($className, 'page_') === 0) {
                    $path = $this->app->locatePath(
                        'page',
                        substr($classPath, 5)
                    );
                } else {
                    $path = $this->app->locatePath(
                        'php',
                        $classPath
                    );
                }
            }
        } catch (Exception_PathFinder $e) {
            $e
                ->addMoreInfo('class', $className)
                ->addMoreInfo('namespace', $namespace)
                ->addMoreInfo('orig_class', $origClassName)
                ;
            throw $e;
        }

        if (!is_readable($path)) {
            throw new Exception_PathFinder('addon', $path, $prefix);
        }

        /**/$this->app->pr->next('pathfinder/loadClass/include ');
        /**/$this->app->pr->start('php parsing');
        include_once $path;

        if (!class_exists($origClassName, false) && !interface_exists($origClassName, false)) {
            throw $this->exception('Class is not defined in file or extended class can not be found')
                ->addMoreInfo('file', $path)
                ->addMoreInfo('namespace', $namespace)
                ->addMoreInfo('class', $className)
                ;
        }
        /**/$this->app->pr->stop();

        return $path;
    }
973140
public function loadClass($className)
    {
        if (self::typeExists($className)) {
            return true;
        }

        if ( ! $this->canLoadClass($className)) {
            return false;
        }

        require($this->includePath !== null ? $this->includePath . DIRECTORY_SEPARATOR : '')
               . str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className)
               . $this->fileExtension;

        return self::typeExists($className);
    }
903002
public function addAlias(string $name, string $className)
    {
        $this->aliases[$name] = $className;
        return $this;
    }
558754
public function create(string $className)
    {
        $this->console->writeLine('Please enter the script name for the console app: ');
        $stubFileName = $this->rootpath->to('bin',  $this->console->readLine());
        if (!file_exists($stubFileName)) {
            $this->createFile($stubFileName, $className, 'script.tmpl');
            $this->console->writeLine(
                    'Script for ' . $className . ' created at ' . $stubFileName
            );
        } else {
            $this->console->writeLine(
                    'Script for ' . $className
                    . ' already exists, skipped creating the script'
            );
        }
    }
635950
public static function loadClass($className) {
		if($className === null) {
			throw new WURFL_WURFLException("Unable To Load Class : " . $className);
		}
		if (substr($className, 0, 6) !== WURFL_ClassLoader::CLASS_PREFIX) {
			return false;
		}
		if (!class_exists($className, false)) {
			if (self::$classPath === null) self::$classPath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
			$classFilePath = str_replace('_', DIRECTORY_SEPARATOR, substr($className, 6)) . '.php';
			include self::$classPath.$classFilePath;
		}
		return false;
	}
1007828
public function load($className) {
    // search under baseDir assuming that namespaces match directories
    $filename = $this->baseDir.str_replace("\\", "/", $className).'.php';
    if (file_exists($filename)) {
      include($filename);
    }
  }
889375
public function loadClass($className) {
        $classFound = $this->composerClassLoader->loadClass($className);
        if (!$classFound && !$this->caseSensitiveClassLoading) {
            $classFound = $this->composerClassLoader->loadClass(strtolower($className));
        }
        return $classFound;
    }
193471
public function addNode(string $className): void
    {
        if (isset($this->nodes[$className])) {
            return;
        }

        $this->nodes[$className] = new DocumentGraphNode($className);
    }
190964
public final function load(string $className): bool
    {
        parent::load($className);
        if ($this->psr4->load($className)
         || $this->classMap->load($className)) {
            return true;
        }
        return false;
    }
730176
public function addClass($className){

        $formClass = $this->getClassName();
        if (is_string($formClass)){
            $formClass = explode(" ", $formClass);
        }
        $formClass[] = $className;

        $this->setFormClass($formClass);

        return $this;
    }
473921
private function fillCache(string $className): void
    {
        if (array_key_exists($className, $this->customSortings)) {
            return;
        }

        $class = new ReflectionClass($className);
        $this->customSortings[$className] = $this->getFromAnnotation($class);
    }
1139028
public function addClassMap(string $classname, ?string $newClassname = null, string $shortName = '', int $instanceId = 0): void
    {
        if ($newClassname === null) {
            $newClassname = $classname;
        }
        $this->addCallableMap($classname, function (Container $container) use ($newClassname) {
            return new $newClassname();
        }, $shortName, $instanceId);
    }
884354
public function autoload($className)
    {
        if (substr($className, 0, 8) == 'PhpThumb')
        {
            $filename = $this->getCodeDir() . '/phpthumb/ThumbLib.inc.php';
            /** @noinspection PhpIncludeInspection */
            include_once $filename;
            return class_exists($className, false) || interface_exists($className, false);
        }
        return false;
    }
783067
static public function autoload($className)
    {
        $className = ltrim($className, '\\');
        $fileName  = '';
        $namespace = '';
        if ($lastNsPos = strripos($className, '\\')) {
            $namespace = substr($className, 0, $lastNsPos);
            $className = substr($className, $lastNsPos + 1);
            $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
        }
        $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

        require self::$base . $fileName;
    }
197787
public function build($className)
        {

                if(is_string($className) and $this->offsetExists($className)) {
                        $className =  $this->offsetGet($className);
                        if(is_object($className)) {
                                return $className;
                        }
                }

                // 如果是匿名函数（Anonymous functions），也叫闭包函数（closures）
                if ($className instanceof \Closure) {
                        // 执行闭包函数，并将结果
                        return $this->getClosure($className, $this);
                }
                /** @var \ReflectionClass $reflector */
                $reflector = new \ReflectionClass($className);

                // 检查类是否可实例化, 排除抽象类abstract和对象接口interface
                if (!$reflector->isInstantiable()) {
                        throw new \Exception("Can't instantiate ".$className);
                }

                /** @var \ReflectionMethod $constructor 获取类的构造函数 */
                $constructor = $reflector->getConstructor();
                // 若无构造函数，直接实例化并返回
                if (is_null($constructor)) {
                        return new $className;
                }

                // 取构造函数参数,通过 ReflectionParameter 数组返回参数列表
                $parameters = $constructor->getParameters();
                // 递归解析构造函数的参数
                $dependencies = $this->getDependencies($parameters);
                // 创建一个类的新实例，给出的参数将传递到类的构造函数。
                $class =  $reflector->newInstanceArgs($dependencies);
                $this->aliases[$className] = $class;
                return $class;
        }
370571
public function load($className)
    {
        $this->_classFilename = $className . '.php';
        $this->_includePaths  = explode(PATH_SEPARATOR, get_include_path());
        $classFound           = null;

        if(strpos($this->_classFilename, '\\') !== false)
        {
            $classFound = $this->searchForBackslashNamespacedClass();
        }
        elseif(strpos($this->_classFilename, '_') !== false)
        {
            $classFound = $this->searchForUnderscoreNamespacedClass();
        }
        else
        {
            $classFound = $this->searchForNonNamespacedClass();
        }

        return $classFound;
    }