diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 3783bd22c..0de53a3bf 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/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('Warning: Ambiguous class "'.$ambiguousReference['class'].'" resolution; defined in "'.$ambiguousReference[0].'" and in "'.$ambiguousReference[1].'" files.'); + } + } + ksort($classMap); foreach ($classMap as $class => $code) { $classmapFile .= ' '.var_export($class, true).' => '.$code; diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 5c2859271..500669a28 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/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; diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index d0cd68b79..88fc4132e 100644 --- a/src/Composer/Factory.php +++ b/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 diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index eff1b86a6..6b5049830 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/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']); } /**