瀏覽代碼

Add support for wildcards in exclude-from-classmap, refs #1607

Jordi Boggiano 9 年之前
父節點
當前提交
6c16510743
共有 2 個文件被更改,包括 13 次插入1 次删除
  1. 4 0
      src/Composer/Autoload/AutoloadGenerator.php
  2. 9 1
      tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

+ 4 - 0
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;
                     }

+ 9 - 1
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', '<?php class ClassExcludeMapFoo {}');
         file_put_contents($this->workingDir.'/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
+        $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/long/excluded/excsubpath');
+        file_put_contents($this->workingDir.'/composersrc/long/excluded/excsubpath/foo.php', '<?php class ClassExcludeMapFoo2 {}');
+        file_put_contents($this->workingDir.'/composersrc/long/excluded/excsubpath/bar.php', '<?php class ClassExcludeMapBar {}');
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');