From 6c165107433b7b6c1f177a36fc5fcfe1b198f6fd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 30 Oct 2015 19:12:30 +0000 Subject: [PATCH] Add support for wildcards in exclude-from-classmap, refs #1607 --- src/Composer/Autoload/AutoloadGenerator.php | 4 ++++ tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index c70c20f36..0d3e15ad6 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -690,6 +690,10 @@ FOOTER; // first escape user input $path = preg_quote(trim(strtr($path, '\\', '/'), '/')); + // add support for wildcards * and ** + $path = str_replace('\\*\\*', '.*?', $path); + $path = str_replace('\\*', '[^/]*?', $path); + $autoloads[] = empty($installPath) ? preg_quote(strtr(getcwd(), '\\', '/')) . '/' . $path : preg_quote($installPath) . '/' . $path; continue; } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 0e373702b..8afe87c3b 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -1274,7 +1274,12 @@ EOF; 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'), ), 'classmap' => array('composersrc/'), - 'exclude-from-classmap' => array('/composersrc/excludedTests/', '/composersrc/ClassToExclude.php'), + 'exclude-from-classmap' => array( + '/composersrc/excludedTests/', + '/composersrc/ClassToExclude.php', + '/composersrc/*/excluded/excsubpath', + '**/excsubpath', + ), )); $this->repository->expects($this->once()) @@ -1300,6 +1305,9 @@ EOF; $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/excludedTests'); file_put_contents($this->workingDir.'/composersrc/excludedTests/bar.php', 'workingDir.'/composersrc/ClassToExclude.php', 'fs->ensureDirectoryExists($this->workingDir.'/composersrc/long/excluded/excsubpath'); + file_put_contents($this->workingDir.'/composersrc/long/excluded/excsubpath/foo.php', 'workingDir.'/composersrc/long/excluded/excsubpath/bar.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');