public function createAutoloader($files = array(), $filename = 'autoloader.php')
    {
        $sourceDir = realpath($this->stageDir);
        $iter = new \RecursiveDirectoryIterator($sourceDir);
        $iter = new \RecursiveIteratorIterator($iter);

        $this->startSection('autoloader');
        $this->debug('Creating classmap autoloader');
        $this->debug("Collecting valid PHP files from {$this->stageDir}");

        $classMap = array();
        foreach ($iter as $file) {
            if ($file->getExtension() == 'php') {
                $location = str_replace($this->stageDir . '/', '', (string) $file);
                $className = str_replace('/', '\\', $location);
                $className = substr($className, 0, -4);

                // Remove "src\" or "lib\"
                if (strpos($className, 'src\\') === 0
                    || strpos($className, 'lib\\') === 0
                ) {
                    $className = substr($className, 4);
                }

                $classMap[$className] = "__DIR__ . '/$location'";
                $this->debug("Found $className");
            }
        }

        $destFile = $this->stageDir . '/' . $filename;
        $this->debug("Writing autoloader to {$destFile}");

        if (!($h = fopen($destFile, 'w'))) {
            throw new \RuntimeException('Unable to open file for writing');
        }

        $this->debug('Writing classmap files');
        fwrite($h, "<?php\n\n");
        fwrite($h, "\$mapping = array(\n");
        foreach ($classMap as $c => $f) {
            fwrite($h, "    '$c' => $f,\n");
        }
        fwrite($h, ");\n\n");
        fwrite($h, <<<EOT
spl_autoload_register(function (\$class) use (\$mapping) {
    if (isset(\$mapping[\$class])) {
        require \$mapping[\$class];
    }
}, true);

EOT
        );

        fwrite($h, "\n");

        $this->debug('Writing automatically included files');
        foreach ($files as $file) {
            fwrite($h, "require __DIR__ . '/$file';\n");
        }

        fclose($h);

        $this->endSection();
    }
public function createAutoloader($files = array(), $filename = 'autoloader.php')
    {
        $sourceDir = realpath($this->stageDir);
        $iter = new \RecursiveDirectoryIterator($sourceDir);
        $iter = new \RecursiveIteratorIterator($iter);

        $this->startSection('autoloader');
        $this->debug('Creating classmap autoloader');
        $this->debug("Collecting valid PHP files from {$this->stageDir}");

        $classMap = array();
        foreach ($iter as $file) {
            if ($file->getExtension() == 'php') {
                $location = str_replace($this->stageDir . '/', '', (string) $file);
                $className = str_replace('/', '\\', $location);
                $className = substr($className, 0, -4);

                // Remove "src\" or "lib\"
                if (strpos($className, 'src\\') === 0
                    || strpos($className, 'lib\\') === 0
                ) {
                    $className = substr($className, 4);
                }

                $classMap[$className] = "__DIR__ . '/$location'";
                $this->debug("Found $className");
            }
        }

        $destFile = $this->stageDir . '/' . $filename;
        $this->debug("Writing autoloader to {$destFile}");

        if (!($h = fopen($destFile, 'w'))) {
            throw new \RuntimeException('Unable to open file for writing');
        }

        $this->debug('Writing classmap files');
        fwrite($h, "<?php\n\n");
        fwrite($h, "\$mapping = array(\n");
        foreach ($classMap as $c => $f) {
            fwrite($h, "    '$c' => $f,\n");
        }
        fwrite($h, ");\n\n");
        fwrite($h, <<<EOT
spl_autoload_register(function (\$class) use (\$mapping) {
    if (isset(\$mapping[\$class])) {
        require \$mapping[\$class];
    }
}, true);

EOT
        );

        fwrite($h, "\n");

        $this->debug('Writing automatically included files');
        foreach ($files as $file) {
            fwrite($h, "require __DIR__ . '/$file';\n");
        }

        fclose($h);

        $this->endSection();
    }
public function createAutoloader ( $ files = array ( ) , $ filename = 'autoloader.php' ) { $ sourceDir = realpath ( $ this -> stageDir ) ; $ iter = new \ RecursiveDirectoryIterator ( $ sourceDir ) ; $ iter = new \ RecursiveIteratorIterator ( $ iter ) ; $ this -> startSection ( 'autoloader' ) ; $ this -> debug ( 'Creating classmap autoloader' ) ; $ this -> debug ( "Collecting valid PHP files from {$this->stageDir}" ) ; $ classMap = array ( ) ; foreach ( $ iter as $ file ) { if ( $ file -> getExtension ( ) == 'php' ) { $ location = str_replace ( $ this -> stageDir . '/' , '' , ( string ) $ file ) ; $ className = str_replace ( '/' , '\\' , $ location ) ; $ className = substr ( $ className , 0 , - 4 ) ; // Remove "src\" or "lib\" if ( strpos ( $ className , 'src\\' ) === 0 || strpos ( $ className , 'lib\\' ) === 0 ) { $ className = substr ( $ className , 4 ) ; } $ classMap [ $ className ] = "__DIR__ . '/$location'" ; $ this -> debug ( "Found $className" ) ; } } $ destFile = $ this -> stageDir . '/' . $ filename ; $ this -> debug ( "Writing autoloader to {$destFile}" ) ; if ( ! ( $ h = fopen ( $ destFile , 'w' ) ) ) { throw new \ RuntimeException ( 'Unable to open file for writing' ) ; } $ this -> debug ( 'Writing classmap files' ) ; fwrite ( $ h , "<?php\n\n" ) ; fwrite ( $ h , "\$mapping = array(\n" ) ; foreach ( $ classMap as $ c => $ f ) { fwrite ( $ h , "    '$c' => $f,\n" ) ; } fwrite ( $ h , ");\n\n" ) ; fwrite ( $ h ,  <<<EOT
spl_autoload_register(function (\$class) use (\$mapping) {
    if (isset(\$mapping[\$class])) {
        require \$mapping[\$class];
    }
}, true);

EOT ) ; fwrite ( $ h , "\n" ) ; $ this -> debug ( 'Writing automatically included files' ) ; foreach ( $ files as $ file ) { fwrite ( $ h , "require __DIR__ . '/$file';\n" ) ; } fclose ( $ h ) ; $ this -> endSection ( ) ; }
Creates a class-map autoloader to the staging directory in a file
named autoloader.php

@param array $files Files to explicitly require in the autoloader. This
is similar to Composer's "files" "autoload" section.
@param string $filename Name of the autoloader file.
@throws \RuntimeException if the file cannot be written
Creates a class - map autoloader to the staging directory in a file named autoloader . php