From f98a8f472ebf645e1a5e177d1938b3a3c2ec1e5f Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Tue, 23 Jul 2013 13:48:55 +0200 Subject: [PATCH] Generate an autoload_files.php next to autoload_namespaces.php and autoload_classes.php --- src/Composer/Autoload/AutoloadGenerator.php | 7 ++++++- tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 8 +++++--- tests/Composer/Test/Autoload/Fixtures/autoload_files.php | 4 ++++ .../Fixtures/autoload_files_files_by_dependency.php | 8 ++++++++ .../Test/Autoload/Fixtures/autoload_files_functions.php | 7 +++++++ .../Test/Autoload/Fixtures/autoload_files_target_dir.php | 4 ++++ .../Fixtures/autoload_real_files_by_dependency.php | 7 +------ .../Test/Autoload/Fixtures/autoload_real_functions.php | 6 +----- .../Test/Autoload/Fixtures/autoload_real_target_dir.php | 3 +-- 9 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_files.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_files_files_by_dependency.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_files_target_dir.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 5f8e4477e..675d3f9d1 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -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 = "getAutoloadFile($vendorPathToTargetDirCode, $suffix)); file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath)); diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 9f54c3791..fea0cdab2 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -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() diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files.php new file mode 100644 index 000000000..47b17f8b0 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files.php @@ -0,0 +1,4 @@ +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; } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index ac167bd83..729f9c7ed 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -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; } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index 2d66cf16f..95212ef0a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -40,8 +40,7 @@ class ComposerAutoloaderInitTargetDir $loader->register(true); - require $baseDir . '/foo.php'; - require $baseDir . '/bar.php'; + require __DIR__ . '/autoload_files.php'; return $loader; }