1
0
Fork 0

Generate an autoload_files.php next to autoload_namespaces.php and autoload_classes.php

pull/2139/head
Andreas Hennings 2013-07-23 13:48:55 +02:00
parent 5b042943e3
commit f98a8f472e
9 changed files with 37 additions and 17 deletions

View File

@ -170,7 +170,7 @@ EOF;
$filesCode = "";
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
foreach ($autoloads['files'] as $functionFile) {
$filesCode .= ' require '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).";\n";
$filesCode .= 'require '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).";\n";
}
if (!$suffix) {
@ -182,6 +182,11 @@ EOF;
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
}
if ($filesCode) {
$filesCode = "<?php\n\n".rtrim($filesCode)."\n";
file_put_contents($targetDir.'/autoload_files.php', $filesCode);
$filesCode = " require __DIR__ . '/autoload_files.php';";
}
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath));

View File

@ -191,6 +191,7 @@ class AutoloadGeneratorTest extends TestCase
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php');
$this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap');
}
@ -374,6 +375,7 @@ class AutoloadGeneratorTest extends TestCase
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
include $this->vendorDir . '/autoload.php';
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
@ -753,8 +755,8 @@ EOF;
$this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php'));
$this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
$this->assertContains("require \$vendorDir . '/b/b/bootstrap.php';", file_get_contents($vendorDir.'/composer/autoload_real.php'));
$this->assertContains("require \$baseDir . '/test.php';", file_get_contents($vendorDir.'/composer/autoload_real.php'));
$this->assertContains("require \$vendorDir . '/b/b/bootstrap.php';", file_get_contents($vendorDir.'/composer/autoload_files.php'));
$this->assertContains("require \$baseDir . '/test.php';", file_get_contents($vendorDir.'/composer/autoload_files.php'));
}
public function testUpLevelRelativePaths()
@ -813,7 +815,7 @@ EOF;
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
$this->assertContains("require \$baseDir . '/../test.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertContains("require \$baseDir . '/../test.php';", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
}
public function testEmptyPaths()

View File

@ -0,0 +1,4 @@
<?php
require $baseDir . '/foo.php';
require $baseDir . '/bar.php';

View File

@ -0,0 +1,8 @@
<?php
require $vendorDir . '/c/lorem/testC.php';
require $vendorDir . '/z/foo/testA.php';
require $vendorDir . '/d/d/testD.php';
require $vendorDir . '/b/bar/testB.php';
require $vendorDir . '/e/e/testE.php';
require $baseDir . '/root.php';

View File

@ -0,0 +1,7 @@
<?php
require $vendorDir . '/a/a/test.php';
require $vendorDir . '/b/b/test2.php';
require $vendorDir . '/c/c/foo/bar/test3.php';
require $baseDir . '/root.php';
require $vendorDir . '/c/c/foo/bar/test4.php';

View File

@ -0,0 +1,4 @@
<?php
require $baseDir . '/foo.php';
require $baseDir . '/bar.php';

View File

@ -38,12 +38,7 @@ class ComposerAutoloaderInitFilesAutoloadOrder
$loader->register(true);
require $vendorDir . '/c/lorem/testC.php';
require $vendorDir . '/z/foo/testA.php';
require $vendorDir . '/d/d/testD.php';
require $vendorDir . '/b/bar/testB.php';
require $vendorDir . '/e/e/testE.php';
require $baseDir . '/root.php';
require __DIR__ . '/autoload_files.php';
return $loader;
}

View File

@ -38,11 +38,7 @@ class ComposerAutoloaderInitFilesAutoload
$loader->register(true);
require $vendorDir . '/a/a/test.php';
require $vendorDir . '/b/b/test2.php';
require $vendorDir . '/c/c/foo/bar/test3.php';
require $baseDir . '/root.php';
require $vendorDir . '/c/c/foo/bar/test4.php';
require __DIR__ . '/autoload_files.php';
return $loader;
}

View File

@ -40,8 +40,7 @@ class ComposerAutoloaderInitTargetDir
$loader->register(true);
require $baseDir . '/foo.php';
require $baseDir . '/bar.php';
require __DIR__ . '/autoload_files.php';
return $loader;
}