Add aliasing: `foo as bar` will require foo and automatically make it replace the bar version
parent
5eb333680b
commit
82054f2060
|
@ -21,6 +21,7 @@ use Composer\DependencyResolver\Pool;
|
||||||
use Composer\DependencyResolver\Request;
|
use Composer\DependencyResolver\Request;
|
||||||
use Composer\DependencyResolver\Operation;
|
use Composer\DependencyResolver\Operation;
|
||||||
use Composer\Package\MemoryPackage;
|
use Composer\Package\MemoryPackage;
|
||||||
|
use Composer\Package\Link;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
|
@ -92,8 +93,10 @@ EOT
|
||||||
$composer->getDownloadManager()->setPreferSource(true);
|
$composer->getDownloadManager()->setPreferSource(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$repoManager = $composer->getRepositoryManager();
|
||||||
|
|
||||||
// create local repo, this contains all packages that are installed in the local project
|
// create local repo, this contains all packages that are installed in the local project
|
||||||
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
|
$localRepo = $repoManager->getLocalRepository();
|
||||||
// create installed repo, this contains all local packages + platform packages (php & extensions)
|
// create installed repo, this contains all local packages + platform packages (php & extensions)
|
||||||
$installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository()));
|
$installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository()));
|
||||||
if ($additionalInstalledRepository) {
|
if ($additionalInstalledRepository) {
|
||||||
|
@ -103,7 +106,7 @@ EOT
|
||||||
// creating repository pool
|
// creating repository pool
|
||||||
$pool = new Pool;
|
$pool = new Pool;
|
||||||
$pool->addRepository($installedRepo);
|
$pool->addRepository($installedRepo);
|
||||||
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
foreach ($repoManager->getRepositories() as $repository) {
|
||||||
$pool->addRepository($repository);
|
$pool->addRepository($repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +151,27 @@ EOT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare aliased packages
|
||||||
|
foreach ($composer->getPackage()->getAliases() as $alias) {
|
||||||
|
$candidates = array_merge(
|
||||||
|
$repoManager->findPackages($alias['package'], $alias['version']),
|
||||||
|
$repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version'])
|
||||||
|
);
|
||||||
|
foreach ($candidates as $package) {
|
||||||
|
$replaces = $package->getReplaces();
|
||||||
|
foreach ($replaces as $index => $link) {
|
||||||
|
// link is self.version, but must be replacing also the replaced version
|
||||||
|
if ('self.version' === $link->getPrettyConstraint()) {
|
||||||
|
$replaces[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $alias['replaces']), 'replaces', $alias['replaces']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add replace of itself
|
||||||
|
$replaces[] = new Link($alias['package'], $alias['package'], new VersionConstraint('=', $alias['replaces']), 'replaces', $alias['replaces']);
|
||||||
|
$package->setReplaces($replaces);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// prepare solver
|
// prepare solver
|
||||||
$installationManager = $composer->getInstallationManager();
|
$installationManager = $composer->getInstallationManager();
|
||||||
$policy = new DependencyResolver\DefaultPolicy();
|
$policy = new DependencyResolver\DefaultPolicy();
|
||||||
|
@ -179,7 +203,7 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
// force update
|
// force update
|
||||||
$newPackage = $composer->getRepositoryManager()->findPackage($package->getName(), $package->getVersion());
|
$newPackage = $repoManager->findPackage($package->getName(), $package->getVersion());
|
||||||
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
|
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
|
||||||
$operations[] = new UpdateOperation($package, $newPackage);
|
$operations[] = new UpdateOperation($package, $newPackage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,21 @@ class RootPackageLoader extends ArrayLoader
|
||||||
|
|
||||||
$package = parent::load($config);
|
$package = parent::load($config);
|
||||||
|
|
||||||
|
if (isset($config['require'])) {
|
||||||
|
$aliases = array();
|
||||||
|
foreach ($config['require'] as $reqName => $reqVersion) {
|
||||||
|
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $reqVersion, $match)) {
|
||||||
|
$aliases[] = array(
|
||||||
|
'package' => strtolower($reqName),
|
||||||
|
'version' => $this->versionParser->normalize($match[1]),
|
||||||
|
'replaces' => $this->versionParser->normalize($match[2]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$package->setAliases($aliases);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($config['repositories'])) {
|
if (isset($config['repositories'])) {
|
||||||
foreach ($config['repositories'] as $index => $repo) {
|
foreach ($config['repositories'] as $index => $repo) {
|
||||||
if (isset($repo['packagist']) && $repo['packagist'] === false) {
|
if (isset($repo['packagist']) && $repo['packagist'] === false) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ class MemoryPackage extends BasePackage
|
||||||
protected $extra = array();
|
protected $extra = array();
|
||||||
protected $binaries = array();
|
protected $binaries = array();
|
||||||
protected $scripts = array();
|
protected $scripts = array();
|
||||||
|
protected $aliases = array();
|
||||||
protected $dev;
|
protected $dev;
|
||||||
|
|
||||||
protected $requires = array();
|
protected $requires = array();
|
||||||
|
@ -156,6 +157,22 @@ class MemoryPackage extends BasePackage
|
||||||
return $this->scripts;
|
return $this->scripts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $aliases
|
||||||
|
*/
|
||||||
|
public function setAliases(array $aliases)
|
||||||
|
{
|
||||||
|
$this->aliases = $aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getAliases()
|
||||||
|
{
|
||||||
|
return $this->aliases;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -34,6 +34,11 @@ class VersionParser
|
||||||
{
|
{
|
||||||
$version = trim($version);
|
$version = trim($version);
|
||||||
|
|
||||||
|
// ignore aliases and just assume the alias is required instead of the source
|
||||||
|
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
|
||||||
|
$version = $match[1];
|
||||||
|
}
|
||||||
|
|
||||||
// match master-like branches
|
// match master-like branches
|
||||||
if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
|
if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
|
||||||
return '9999999-dev';
|
return '9999999-dev';
|
||||||
|
|
|
@ -53,6 +53,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
'parses trunk' => array('dev-trunk', '9999999-dev'),
|
'parses trunk' => array('dev-trunk', '9999999-dev'),
|
||||||
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
|
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
|
||||||
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-foobar'),
|
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-foobar'),
|
||||||
|
'ignores aliases' => array('dev-master as 1.0.0', '9999999-dev'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue