Skip to content
Browse files

Make PSR0 scanning optional

  • Loading branch information...
1 parent ee14950 commit 44d7d4a38e221209ef0e3c6f64d1bbcba3ab5779 @Seldaek Seldaek committed Aug 14, 2012
Showing with 29 additions and 26 deletions.
  1. +17 −14 src/Composer/Autoload/AutoloadGenerator.php
  2. +12 −12 tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
View
31 src/Composer/Autoload/AutoloadGenerator.php
@@ -25,7 +25,7 @@
*/
class AutoloadGenerator
{
- public function dump(Config $config, RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $suffix = '')
+ public function dump(Config $config, RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
{
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
@@ -118,19 +118,22 @@ public static function autoload(\$class)
// flatten array
$classMap = array();
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
- foreach ($autoloads['psr-0'] as $namespace => $paths) {
- foreach ($paths as $dir) {
- $dir = $this->getPath($filesystem, $relVendorPath, $vendorPath, $dir);
- $whitelist = sprintf(
- '{%s/%s.+(?<!(?<!/)Test\.php)$}',
- preg_quote(rtrim($dir, '/')),
- strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : ''
- );
- foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
- if (0 === strpos($class, $namespace)) {
- $path = '/'.$filesystem->findShortestPath(getcwd(), $path, true);
- if (!isset($classMap[$class])) {
- $classMap[$class] = '$baseDir . '.var_export($path, true).",\n";
+
+ if ($scanPsr0Packages) {
+ foreach ($autoloads['psr-0'] as $namespace => $paths) {
+ foreach ($paths as $dir) {
+ $dir = $this->getPath($filesystem, $relVendorPath, $vendorPath, $dir);
+ $whitelist = sprintf(
+ '{%s/%s.+(?<!(?<!/)Test\.php)$}',
+ preg_quote(rtrim($dir, '/')),
+ strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : ''
+ );
+ foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
+ if (0 === strpos($class, $namespace)) {
+ $path = '/'.$filesystem->findShortestPath(getcwd(), $path, true);
+ if (!isset($classMap[$class])) {
+ $classMap[$class] = '$baseDir . '.var_export($path, true).",\n";
+ }
}
}
}
View
24 tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
@@ -92,7 +92,7 @@ public function testMainPackageAutoloading()
$this->createClassFile($this->workingDir);
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_1');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_1');
$this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
}
@@ -117,7 +117,7 @@ public function testVendorDirSameAsWorkingDir()
$this->createClassFile($this->vendorDir);
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_2');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_2');
$this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
}
@@ -140,7 +140,7 @@ public function testMainPackageAutoloadingAlternativeVendorDir()
$this->fs->ensureDirectoryExists($this->workingDir.'/src');
$this->createClassFile($this->workingDir);
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_3');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_3');
$this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
}
@@ -159,7 +159,7 @@ public function testMainPackageAutoloadingWithTargetDir()
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', 'TargetDir');
+ $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_realTargetDir.php');
}
@@ -184,7 +184,7 @@ public function testVendorsAutoloading()
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_5');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
}
@@ -211,7 +211,7 @@ public function testVendorsClassMapAutoloading()
file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_6');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
$this->assertEquals(
array(
@@ -248,7 +248,7 @@ public function testClassMapAutoloadingEmptyDirAndExactFile()
file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_7');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
$this->assertEquals(
array(
@@ -280,7 +280,7 @@ public function testFilesAutoloadGeneration()
file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', 'FilesAutoload');
+ $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_realFilesAutoload.php');
@@ -346,7 +346,7 @@ public function testOverrideVendorsAutoloading()
EOF;
- $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', '_9');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_9');
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
}
@@ -375,7 +375,7 @@ public function testIncludePathFileGeneration()
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
- $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", '_10');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_10');
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
$this->assertEquals(
@@ -404,7 +404,7 @@ public function testIncludePathsArePrependedInAutoloadFile()
mkdir($this->vendorDir."/composer", 0777, true);
- $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", '_11');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_11');
$oldIncludePath = get_include_path();
@@ -435,7 +435,7 @@ public function testIncludePathFileWithoutPathsIsSkipped()
mkdir($this->vendorDir."/composer", 0777, true);
- $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", '_12');
+ $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
$this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
}

0 comments on commit 44d7d4a

Please sign in to comment.
Something went wrong with that request. Please try again.