Forráskód Böngészése

show warning only instead of throwing exception

Jan Brecka 11 éve
szülő
commit
b94838169d

+ 14 - 1
src/Composer/Autoload/AutoloadGenerator.php

@@ -15,6 +15,7 @@ namespace Composer\Autoload;
 use Composer\Config;
 use Composer\EventDispatcher\EventDispatcher;
 use Composer\Installer\InstallationManager;
+use Composer\IO\IOInterface;
 use Composer\Package\AliasPackage;
 use Composer\Package\PackageInterface;
 use Composer\Repository\InstalledRepositoryInterface;
@@ -32,11 +33,17 @@ class AutoloadGenerator
      */
     private $eventDispatcher;
 
+    /**
+     * @var IOInterface
+     */
+    private $io;
+
     private $devMode = false;
 
-    public function __construct(EventDispatcher $eventDispatcher)
+    public function __construct(EventDispatcher $eventDispatcher, IOInterface $io=null)
     {
         $this->eventDispatcher = $eventDispatcher;
+        $this->io = $io;
     }
 
     public function setDevMode($devMode = true)
@@ -197,6 +204,12 @@ EOF;
             }
         }
 
+        if ($this->io && count(ClassMapGenerator::$ambiguousReferences) > 0) {
+            foreach (ClassMapGenerator::$ambiguousReferences as $ambiguousReference) {
+                $this->io->write('<info>Warning: Ambiguous class "'.$ambiguousReference['class'].'" resolution; defined in "'.$ambiguousReference[0].'" and in "'.$ambiguousReference[1].'" files.</info>');
+            }
+        }
+
         ksort($classMap);
         foreach ($classMap as $class => $code) {
             $classmapFile .= '    '.var_export($class, true).' => '.$code;

+ 11 - 1
src/Composer/Autoload/ClassMapGenerator.php

@@ -21,6 +21,12 @@ use Symfony\Component\Finder\Finder;
  */
 class ClassMapGenerator
 {
+
+    /**
+     * @var array
+     */
+    public static $ambiguousReferences = array();
+
     /**
      * Generate a class map file
      *
@@ -80,7 +86,11 @@ class ClassMapGenerator
 
             foreach ($classes as $class) {
                 if (array_key_exists($class, $map)) {
-                    throw new \RuntimeException('Ambiguous class "'.$class.'" resolution; defined in "'.$map[$class].'" and in "'.$filePath.'" files.');
+                    self::$ambiguousReferences[] = array(
+                        'class' => $class,
+                        '0' => $map[$class],
+                        '1' => $filePath
+                    );
                 }
 
                 $map[$class] = $filePath;

+ 1 - 1
src/Composer/Factory.php

@@ -253,7 +253,7 @@ class Factory
         $composer->setEventDispatcher($dispatcher);
 
         // initialize autoload generator
-        $generator = new AutoloadGenerator($dispatcher);
+        $generator = new AutoloadGenerator($dispatcher, $io);
         $composer->setAutoloadGenerator($generator);
 
         // add installers to the manager

+ 3 - 4
tests/Composer/Test/Autoload/ClassMapGeneratorTest.php

@@ -102,10 +102,6 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
 
         $find->invoke(null, __DIR__.'/no-file');
     }
-
-    /**
-     * @expectedException \RuntimeException
-     */
     public function testAmbiguousReference()
     {
         $this->checkIfFinderIsAvailable();
@@ -114,6 +110,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
         $finder->files()->in(__DIR__ . '/Fixtures/Ambiguous');
 
         ClassMapGenerator::createMap($finder);
+
+        $this->assertEquals(1, count(ClassMapGenerator::$ambiguousReferences));
+        $this->assertEquals('A', ClassMapGenerator::$ambiguousReferences[0]['class']);
     }
 
     /**