1
0
Fork 0

Add RootAliasPackage, fixes #1842

pull/1850/head
Jordi Boggiano 2013-04-30 10:37:03 +02:00
parent 9d814c948e
commit b9a44a0057
5 changed files with 131 additions and 12 deletions

View File

@ -174,11 +174,14 @@ class Installer
$this->downloadManager->setPreferDist(true); $this->downloadManager->setPreferDist(true);
} }
// create installed repo, this contains all local packages + platform packages (php & extensions) // clone root package to have one in the installed repo that does not require anything
// we don't want it to be uninstallable, but its requirements should not conflict
// with the lock file for example
$installedRootPackage = clone $this->package; $installedRootPackage = clone $this->package;
$installedRootPackage->setRequires(array()); $installedRootPackage->setRequires(array());
$installedRootPackage->setDevRequires(array()); $installedRootPackage->setDevRequires(array());
// create installed repo, this contains all local packages + platform packages (php & extensions)
$localRepo = $this->repositoryManager->getLocalRepository(); $localRepo = $this->repositoryManager->getLocalRepository();
$platformRepo = new PlatformRepository(); $platformRepo = new PlatformRepository();
$repos = array( $repos = array(

View File

@ -14,6 +14,8 @@ namespace Composer\Package\Loader;
use Composer\Package; use Composer\Package;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\RootAliasPackage;
use Composer\Package\RootPackageInterface;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
/** /**
@ -184,7 +186,11 @@ class ArrayLoader implements LoaderInterface
} }
if ($aliasNormalized = $this->getBranchAlias($config)) { if ($aliasNormalized = $this->getBranchAlias($config)) {
$package = new AliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized)); if ($package instanceof RootPackageInterface) {
$package = new RootAliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
} else {
$package = new AliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
}
} }
return $package; return $package;

View File

@ -65,10 +65,10 @@ class RootPackageLoader extends ArrayLoader
$version = $config['version']; $version = $config['version'];
} }
$package = parent::load($config, $class); $realPackage = $package = parent::load($config, $class);
if ($package instanceof AliasPackage) { if ($realPackage instanceof AliasPackage) {
$package = $package->getAliasOf(); $realPackage = $package->getAliasOf();
} }
$aliases = array(); $aliases = array();
@ -79,7 +79,7 @@ class RootPackageLoader extends ArrayLoader
$linkInfo = BasePackage::$supportedLinkTypes[$linkType]; $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
$method = 'get'.ucfirst($linkInfo['method']); $method = 'get'.ucfirst($linkInfo['method']);
$links = array(); $links = array();
foreach ($package->$method() as $link) { foreach ($realPackage->$method() as $link) {
$links[$link->getTarget()] = $link->getConstraint()->getPrettyString(); $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
} }
$aliases = $this->extractAliases($links, $aliases); $aliases = $this->extractAliases($links, $aliases);
@ -88,23 +88,23 @@ class RootPackageLoader extends ArrayLoader
} }
} }
$package->setAliases($aliases); $realPackage->setAliases($aliases);
$package->setStabilityFlags($stabilityFlags); $realPackage->setStabilityFlags($stabilityFlags);
$package->setReferences($references); $realPackage->setReferences($references);
if (isset($config['minimum-stability'])) { if (isset($config['minimum-stability'])) {
$package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
} }
if (isset($config['prefer-stable'])) { if (isset($config['prefer-stable'])) {
$package->setPreferStable((bool) $config['prefer-stable']); $realPackage->setPreferStable((bool) $config['prefer-stable']);
} }
$repos = Factory::createDefaultRepositories(null, $this->config, $this->manager); $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
foreach ($repos as $repo) { foreach ($repos as $repo) {
$this->manager->addRepository($repo); $this->manager->addRepository($repo);
} }
$package->setRepositories($this->config->getRepositories()); $realPackage->setRepositories($this->config->getRepositories());
return $package; return $package;
} }

View File

@ -0,0 +1,89 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Package;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Package\Version\VersionParser;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class RootAliasPackage extends AliasPackage implements RootPackageInterface
{
public function __construct(RootPackageInterface $aliasOf, $version, $prettyVersion)
{
parent::__construct($aliasOf, $version, $prettyVersion);
}
/**
* {@inheritDoc}
*/
public function getAliases()
{
return $this->aliasOf->getAliases();
}
/**
* {@inheritDoc}
*/
public function getMinimumStability()
{
return $this->aliasOf->getMinimumStability();
}
/**
* {@inheritDoc}
*/
public function getStabilityFlags()
{
return $this->aliasOf->getStabilityFlags();
}
/**
* {@inheritDoc}
*/
public function getReferences()
{
return $this->aliasOf->getReferences();
}
/**
* {@inheritDoc}
*/
public function getPreferStable()
{
return $this->aliasOf->getPreferStable();
}
/**
* {@inheritDoc}
*/
public function setRequires(array $require)
{
return $this->aliasOf->setRequires($require);
}
/**
* {@inheritDoc}
*/
public function setDevRequires(array $devRequire)
{
return $this->aliasOf->setDevRequires($devRequire);
}
public function __clone()
{
parent::__clone();
$this->aliasOf = clone $this->aliasOf;
}
}

View File

@ -50,4 +50,25 @@ interface RootPackageInterface extends CompletePackageInterface
* @return array * @return array
*/ */
public function getReferences(); public function getReferences();
/**
* Returns true if the root package prefers picking stable packages over unstable ones
*
* @return bool
*/
public function getPreferStable();
/**
* Set the required packages
*
* @param array $requires A set of package links
*/
public function setRequires(array $requires);
/**
* Set the recommended packages
*
* @param array $devRequires A set of package links
*/
public function setDevRequires(array $devRequires);
} }