Added support for the alias of an aliased package
parent
c39e958a6f
commit
753a8345cb
|
@ -170,12 +170,14 @@ class Pool
|
||||||
$name = $package->getName();
|
$name = $package->getName();
|
||||||
if (isset($rootAliases[$name][$package->getVersion()])) {
|
if (isset($rootAliases[$name][$package->getVersion()])) {
|
||||||
$alias = $rootAliases[$name][$package->getVersion()];
|
$alias = $rootAliases[$name][$package->getVersion()];
|
||||||
$package->setAlias($alias['alias_normalized']);
|
if ($package instanceof AliasPackage) {
|
||||||
$package->setPrettyAlias($alias['alias']);
|
$package = $package->getAliasOf();
|
||||||
$package->getRepository()->addPackage($aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']));
|
}
|
||||||
|
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
|
||||||
$aliasPackage->setRootPackageAlias(true);
|
$aliasPackage->setRootPackageAlias(true);
|
||||||
$aliasPackage->setId($this->id++);
|
$aliasPackage->setId($this->id++);
|
||||||
|
|
||||||
|
$package->getRepository()->addPackage($aliasPackage);
|
||||||
$this->packages[] = $aliasPackage;
|
$this->packages[] = $aliasPackage;
|
||||||
|
|
||||||
foreach ($aliasPackage->getNames() as $name) {
|
foreach ($aliasPackage->getNames() as $name) {
|
||||||
|
|
|
@ -687,8 +687,6 @@ class Installer
|
||||||
foreach ($versions as $version => $alias) {
|
foreach ($versions as $version => $alias) {
|
||||||
$packages = $platformRepo->findPackages($package, $version);
|
$packages = $platformRepo->findPackages($package, $version);
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
$package->setAlias($alias['alias_normalized']);
|
|
||||||
$package->setPrettyAlias($alias['alias']);
|
|
||||||
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
|
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
|
||||||
$aliasPackage->setRootPackageAlias(true);
|
$aliasPackage->setRootPackageAlias(true);
|
||||||
$platformRepo->addPackage($aliasPackage);
|
$platformRepo->addPackage($aliasPackage);
|
||||||
|
|
|
@ -175,22 +175,6 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
|
||||||
return $this->rootPackageAlias;
|
return $this->rootPackageAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAlias()
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getPrettyAlias()
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************
|
/***************************************
|
||||||
* Wrappers around the aliased package *
|
* Wrappers around the aliased package *
|
||||||
***************************************/
|
***************************************/
|
||||||
|
@ -251,14 +235,6 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
|
||||||
{
|
{
|
||||||
return $this->aliasOf->getScripts();
|
return $this->aliasOf->getScripts();
|
||||||
}
|
}
|
||||||
public function setAliases(array $aliases)
|
|
||||||
{
|
|
||||||
return $this->aliasOf->setAliases($aliases);
|
|
||||||
}
|
|
||||||
public function getAliases()
|
|
||||||
{
|
|
||||||
return $this->aliasOf->getAliases();
|
|
||||||
}
|
|
||||||
public function getLicense()
|
public function getLicense()
|
||||||
{
|
{
|
||||||
return $this->aliasOf->getLicense();
|
return $this->aliasOf->getLicense();
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer\Package\Loader;
|
namespace Composer\Package\Loader;
|
||||||
|
|
||||||
use Composer\Package;
|
use Composer\Package;
|
||||||
|
use Composer\Package\AliasPackage;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,11 +101,6 @@ class ArrayLoader implements LoaderInterface
|
||||||
$package->setDistSha1Checksum(isset($config['dist']['shasum']) ? $config['dist']['shasum'] : null);
|
$package->setDistSha1Checksum(isset($config['dist']['shasum']) ? $config['dist']['shasum'] : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($aliasNormalized = $this->getBranchAlias($config)) {
|
|
||||||
$package->setAlias($aliasNormalized);
|
|
||||||
$package->setPrettyAlias(preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Package\BasePackage::$supportedLinkTypes as $type => $opts) {
|
foreach (Package\BasePackage::$supportedLinkTypes as $type => $opts) {
|
||||||
if (isset($config[$type])) {
|
if (isset($config[$type])) {
|
||||||
$method = 'set'.ucfirst($opts['method']);
|
$method = 'set'.ucfirst($opts['method']);
|
||||||
|
@ -187,6 +183,10 @@ class ArrayLoader implements LoaderInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($aliasNormalized = $this->getBranchAlias($config)) {
|
||||||
|
$package = new AliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
|
||||||
|
}
|
||||||
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,6 @@ class Package extends BasePackage
|
||||||
protected $releaseDate;
|
protected $releaseDate;
|
||||||
protected $extra = array();
|
protected $extra = array();
|
||||||
protected $binaries = array();
|
protected $binaries = array();
|
||||||
protected $aliases = array();
|
|
||||||
protected $alias;
|
|
||||||
protected $prettyAlias;
|
|
||||||
protected $dev;
|
protected $dev;
|
||||||
protected $stability;
|
protected $stability;
|
||||||
protected $notificationUrl;
|
protected $notificationUrl;
|
||||||
|
@ -155,54 +152,6 @@ class Package extends BasePackage
|
||||||
return $this->binaries;
|
return $this->binaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $aliases
|
|
||||||
*/
|
|
||||||
public function setAliases(array $aliases)
|
|
||||||
{
|
|
||||||
$this->aliases = $aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAliases()
|
|
||||||
{
|
|
||||||
return $this->aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $alias
|
|
||||||
*/
|
|
||||||
public function setAlias($alias)
|
|
||||||
{
|
|
||||||
$this->alias = $alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAlias()
|
|
||||||
{
|
|
||||||
return $this->alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $prettyAlias
|
|
||||||
*/
|
|
||||||
public function setPrettyAlias($prettyAlias)
|
|
||||||
{
|
|
||||||
$this->prettyAlias = $prettyAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getPrettyAlias()
|
|
||||||
{
|
|
||||||
return $this->prettyAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -267,20 +267,6 @@ interface PackageInterface
|
||||||
*/
|
*/
|
||||||
public function getBinaries();
|
public function getBinaries();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a version this package should be aliased to
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAlias();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a non-normalized version this package should be aliased to
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPrettyAlias();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns package unique name, constructed from name and version.
|
* Returns package unique name, constructed from name and version.
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,6 +23,7 @@ class RootPackage extends CompletePackage implements RootPackageInterface
|
||||||
protected $preferStable = false;
|
protected $preferStable = false;
|
||||||
protected $stabilityFlags = array();
|
protected $stabilityFlags = array();
|
||||||
protected $references = array();
|
protected $references = array();
|
||||||
|
protected $aliases = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the minimumStability
|
* Set the minimumStability
|
||||||
|
@ -95,4 +96,22 @@ class RootPackage extends CompletePackage implements RootPackageInterface
|
||||||
{
|
{
|
||||||
return $this->references;
|
return $this->references;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the aliases
|
||||||
|
*
|
||||||
|
* @param array $aliases
|
||||||
|
*/
|
||||||
|
public function setAliases(array $aliases)
|
||||||
|
{
|
||||||
|
$this->aliases = $aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getAliases()
|
||||||
|
{
|
||||||
|
return $this->aliases;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,13 @@ namespace Composer\Package;
|
||||||
*/
|
*/
|
||||||
interface RootPackageInterface extends CompletePackageInterface
|
interface RootPackageInterface extends CompletePackageInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Returns a set of package names and theirs aliases
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAliases();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the minimum stability of the package
|
* Returns the minimum stability of the package
|
||||||
*
|
*
|
||||||
|
|
|
@ -124,18 +124,17 @@ class ArrayRepository implements RepositoryInterface
|
||||||
$package->setRepository($this);
|
$package->setRepository($this);
|
||||||
$this->packages[] = $package;
|
$this->packages[] = $package;
|
||||||
|
|
||||||
// create alias package on the fly if needed
|
if ($package instanceof AliasPackage) {
|
||||||
if ($package->getAlias()) {
|
$aliasedPackage = $package->getAliasOf();
|
||||||
$alias = $this->createAliasPackage($package);
|
if (null === $aliasedPackage->getRepository()) {
|
||||||
if (!$this->hasPackage($alias)) {
|
$this->addPackage($aliasedPackage);
|
||||||
$this->addPackage($alias);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createAliasPackage(PackageInterface $package, $alias = null, $prettyAlias = null)
|
protected function createAliasPackage(PackageInterface $package, $alias, $prettyAlias)
|
||||||
{
|
{
|
||||||
return new AliasPackage($package, $alias ?: $package->getAlias(), $prettyAlias ?: $package->getPrettyAlias());
|
return new AliasPackage($package instanceof AliasPackage ? $package->getAliasOf() : $package, $alias, $prettyAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -322,16 +322,18 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
$package = $this->createPackage($version, 'Composer\Package\Package');
|
$package = $this->createPackage($version, 'Composer\Package\Package');
|
||||||
$package->setRepository($this);
|
$package->setRepository($this);
|
||||||
|
|
||||||
|
if ($package instanceof AliasPackage) {
|
||||||
|
$aliased = $package->getAliasOf();
|
||||||
|
$aliased->setRepository($this);
|
||||||
|
|
||||||
|
$this->providers[$name][$version['uid']] = $aliased;
|
||||||
|
$this->providers[$name][$version['uid'].'-alias'] = $package;
|
||||||
|
|
||||||
|
// override provider with its alias so it can be expanded in the if block above
|
||||||
|
$this->providersByUid[$version['uid']] = $package;
|
||||||
|
} else {
|
||||||
$this->providers[$name][$version['uid']] = $package;
|
$this->providers[$name][$version['uid']] = $package;
|
||||||
$this->providersByUid[$version['uid']] = $package;
|
$this->providersByUid[$version['uid']] = $package;
|
||||||
|
|
||||||
if ($package->getAlias()) {
|
|
||||||
$alias = $this->createAliasPackage($package);
|
|
||||||
$alias->setRepository($this);
|
|
||||||
|
|
||||||
$this->providers[$name][$version['uid'].'-alias'] = $alias;
|
|
||||||
// override provider with its alias so it can be expanded in the if block above
|
|
||||||
$this->providersByUid[$version['uid']] = $alias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle root package aliases
|
// handle root package aliases
|
||||||
|
@ -339,8 +341,8 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
|
|
||||||
if (isset($this->rootAliases[$name][$package->getVersion()])) {
|
if (isset($this->rootAliases[$name][$package->getVersion()])) {
|
||||||
$rootAliasData = $this->rootAliases[$name][$package->getVersion()];
|
$rootAliasData = $this->rootAliases[$name][$package->getVersion()];
|
||||||
} elseif (($aliasNormalized = $package->getAlias()) && isset($this->rootAliases[$name][$aliasNormalized])) {
|
} elseif ($package instanceof AliasPackage && isset($this->rootAliases[$name][$package->getAliasOf()->getVersion()])) {
|
||||||
$rootAliasData = $this->rootAliases[$name][$aliasNormalized];
|
$rootAliasData = $this->rootAliases[$name][$package->getAliasOf()->getVersion()];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($rootAliasData)) {
|
if (isset($rootAliasData)) {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
--TEST--
|
||||||
|
Installing double aliased package
|
||||||
|
--COMPOSER--
|
||||||
|
{
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "package",
|
||||||
|
"package": [
|
||||||
|
{
|
||||||
|
"name": "a/a", "version": "dev-master",
|
||||||
|
"dist": { "type": "file", "url": "" },
|
||||||
|
"require": {
|
||||||
|
"b/b": "dev-master"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "b/b", "version": "dev-foo",
|
||||||
|
"extra": { "branch-alias": { "dev-foo": "1.0.x-dev" } },
|
||||||
|
"dist": { "type": "file", "url": "" }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"a/a": "dev-master",
|
||||||
|
"b/b": "1.0.x-dev as dev-master"
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev"
|
||||||
|
}
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
|
--EXPECT--
|
||||||
|
Installing b/b (dev-foo)
|
||||||
|
Marking b/b (dev-master) as installed, alias of b/b (dev-foo)
|
||||||
|
Installing a/a (dev-master)
|
||||||
|
Marking b/b (1.0.x-dev) as installed, alias of b/b (dev-foo)
|
|
@ -67,16 +67,15 @@ class InstallationManagerMock extends InstallationManager
|
||||||
$this->installed[] = $package;
|
$this->installed[] = $package;
|
||||||
$this->trace[] = (string) $operation;
|
$this->trace[] = (string) $operation;
|
||||||
|
|
||||||
if (!$repo->hasPackage($package)) {
|
parent::markAliasInstalled($repo, $operation);
|
||||||
$repo->addPackage($package);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
|
public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
|
||||||
{
|
{
|
||||||
$this->uninstalled[] = $operation->getPackage();
|
$this->uninstalled[] = $operation->getPackage();
|
||||||
$this->trace[] = (string) $operation;
|
$this->trace[] = (string) $operation;
|
||||||
$repo->removePackage($operation->getPackage());
|
|
||||||
|
parent::markAliasUninstalled($repo, $operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTrace()
|
public function getTrace()
|
||||||
|
|
|
@ -123,4 +123,18 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
$dumper = new ArrayDumper;
|
$dumper = new ArrayDumper;
|
||||||
$this->assertEquals($config, $dumper->dump($package));
|
$this->assertEquals($config, $dumper->dump($package));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPackageWithBranchAlias()
|
||||||
|
{
|
||||||
|
$config = array(
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => 'dev-master',
|
||||||
|
'extra' => array('branch-alias' => array('dev-master' => '1.0.x-dev')),
|
||||||
|
);
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
|
||||||
|
$this->assertEquals('1.0.x-dev', $package->getPrettyVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,4 +66,18 @@ class ArrayRepositoryTest extends TestCase
|
||||||
$this->assertCount(2, $bar);
|
$this->assertCount(2, $bar);
|
||||||
$this->assertEquals('bar', $bar[0]->getName());
|
$this->assertEquals('bar', $bar[0]->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAutomaticallyAddAliasedPackage()
|
||||||
|
{
|
||||||
|
$repo = new ArrayRepository();
|
||||||
|
|
||||||
|
$package = $this->getPackage('foo', '1');
|
||||||
|
$alias = $this->getAliasPackage($package, '2');
|
||||||
|
|
||||||
|
$repo->addPackage($alias);
|
||||||
|
|
||||||
|
$this->assertEquals(2, count($repo));
|
||||||
|
$this->assertTrue($repo->hasPackage($this->getPackage('foo', '1')));
|
||||||
|
$this->assertTrue($repo->hasPackage($this->getPackage('foo', '2')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue