Merge remote-tracking branch 'johnikx/ambiguous-reference-warning'
commit
c3ab09750d
|
@ -15,6 +15,7 @@ namespace Composer\Autoload;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
use Composer\EventDispatcher\EventDispatcher;
|
use Composer\EventDispatcher\EventDispatcher;
|
||||||
use Composer\Installer\InstallationManager;
|
use Composer\Installer\InstallationManager;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Package\AliasPackage;
|
use Composer\Package\AliasPackage;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Repository\InstalledRepositoryInterface;
|
use Composer\Repository\InstalledRepositoryInterface;
|
||||||
|
@ -32,11 +33,17 @@ class AutoloadGenerator
|
||||||
*/
|
*/
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var IOInterface
|
||||||
|
*/
|
||||||
|
private $io;
|
||||||
|
|
||||||
private $devMode = false;
|
private $devMode = false;
|
||||||
|
|
||||||
public function __construct(EventDispatcher $eventDispatcher)
|
public function __construct(EventDispatcher $eventDispatcher, IOInterface $io=null)
|
||||||
{
|
{
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
$this->io = $io;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDevMode($devMode = true)
|
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);
|
ksort($classMap);
|
||||||
foreach ($classMap as $class => $code) {
|
foreach ($classMap as $class => $code) {
|
||||||
$classmapFile .= ' '.var_export($class, true).' => '.$code;
|
$classmapFile .= ' '.var_export($class, true).' => '.$code;
|
||||||
|
|
|
@ -21,6 +21,12 @@ use Symfony\Component\Finder\Finder;
|
||||||
*/
|
*/
|
||||||
class ClassMapGenerator
|
class ClassMapGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $ambiguousReferences = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a class map file
|
* Generate a class map file
|
||||||
*
|
*
|
||||||
|
@ -79,6 +85,14 @@ class ClassMapGenerator
|
||||||
$classes = self::findClasses($filePath);
|
$classes = self::findClasses($filePath);
|
||||||
|
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
|
if (array_key_exists($class, $map)) {
|
||||||
|
self::$ambiguousReferences[] = array(
|
||||||
|
'class' => $class,
|
||||||
|
'0' => $map[$class],
|
||||||
|
'1' => $filePath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$map[$class] = $filePath;
|
$map[$class] = $filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ class Factory
|
||||||
$composer->setEventDispatcher($dispatcher);
|
$composer->setEventDispatcher($dispatcher);
|
||||||
|
|
||||||
// initialize autoload generator
|
// initialize autoload generator
|
||||||
$generator = new AutoloadGenerator($dispatcher);
|
$generator = new AutoloadGenerator($dispatcher, $io);
|
||||||
$composer->setAutoloadGenerator($generator);
|
$composer->setAutoloadGenerator($generator);
|
||||||
|
|
||||||
// add installers to the manager
|
// add installers to the manager
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Composer\Test\Autoload;
|
namespace Composer\Test\Autoload;
|
||||||
|
|
||||||
use Composer\Autoload\ClassMapGenerator;
|
use Composer\Autoload\ClassMapGenerator;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
@ -78,11 +79,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testCreateMapFinderSupport()
|
public function testCreateMapFinderSupport()
|
||||||
{
|
{
|
||||||
if (!class_exists('Symfony\\Component\\Finder\\Finder')) {
|
$this->checkIfFinderIsAvailable();
|
||||||
$this->markTestSkipped('Finder component is not available');
|
|
||||||
}
|
|
||||||
|
|
||||||
$finder = new \Symfony\Component\Finder\Finder();
|
$finder = new Finder();
|
||||||
$finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision');
|
$finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision');
|
||||||
|
|
||||||
$this->assertEqualsNormalized(array(
|
$this->assertEqualsNormalized(array(
|
||||||
|
@ -103,6 +102,18 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$find->invoke(null, __DIR__.'/no-file');
|
$find->invoke(null, __DIR__.'/no-file');
|
||||||
}
|
}
|
||||||
|
public function testAmbiguousReference()
|
||||||
|
{
|
||||||
|
$this->checkIfFinderIsAvailable();
|
||||||
|
|
||||||
|
$finder = new Finder();
|
||||||
|
$finder->files()->in(__DIR__ . '/Fixtures/Ambiguous');
|
||||||
|
|
||||||
|
ClassMapGenerator::createMap($finder);
|
||||||
|
|
||||||
|
$this->assertEquals(1, count(ClassMapGenerator::$ambiguousReferences));
|
||||||
|
$this->assertEquals('A', ClassMapGenerator::$ambiguousReferences[0]['class']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
|
@ -123,4 +134,11 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
$this->assertEquals($expected, $actual, $message);
|
$this->assertEquals($expected, $actual, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkIfFinderIsAvailable()
|
||||||
|
{
|
||||||
|
if (!class_exists('Symfony\\Component\\Finder\\Finder')) {
|
||||||
|
$this->markTestSkipped('Finder component is not available');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class A
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class A
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue