1

我正在尝试创建一个自定义自动加载器,它会扫描所有目录并保存每个文件中的类。这就是我所拥有的:

define ('PATH', 'C:\work\Symfony-1.4.20');

$files = array();
$map = array();

function loadClassLoader($name)
{
    global $map, $files;

    foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH)) as $file)
    { 
        $file2 = $file->__toString();

        if (strtolower($file2) != strtolower(__FILE__) && 
            $file->getExtension() == 'php' && 
            !isset($files[$file2]))
        {
            $files[$file2] = true;
            $classesNow = get_declared_classes();                    
            require ($file2);
            foreach (array_diff (get_declared_classes(), $classesNow) as $c)
            {
                $reflection = new ReflectionClass($c);
                $map[$c] = $reflection->getFileName();
                unset ($reflection);
            }            
        }
    }
}

spl_autoload_register('loadClassLoader');

loadClassLoader ('');

echo '<pre>'; var_dump ($map); echo '</pre>';

可悲的是,它不适用于更大的系统。这个逻辑缺少什么?

错误信息是:Fatal error: Class 'BaseForm' not found in C:\Work\symfony-1.4.20\lib\form\addon\sfFormObject.class.php on line 20

4

0 回答 0