1
0
Fork 0

show warning only instead of throwing exception

pull/2828/head
Jan Brecka 2014-03-24 14:34:02 +01:00
parent de09c5e371
commit b94838169d
4 changed files with 29 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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']);
}
/**