1
0
Fork 0

[alias] RootAliasPackage manages the requirements correctly

pull/3982/head
Vadim Tyukov 2013-12-10 11:49:54 +02:00 committed by Jordi Boggiano
parent a811142ff2
commit b02bdb4c7a
2 changed files with 31 additions and 25 deletions

View File

@ -28,6 +28,7 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
protected $stability;
protected $requires;
protected $devRequires;
protected $conflicts;
protected $provides;
protected $replaces;
@ -51,32 +52,15 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
$this->stability = VersionParser::parseStability($version);
$this->dev = $this->stability === 'dev';
// replace self.version dependencies
foreach (array('requires', 'devRequires') as $type) {
foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) {
$links = $aliasOf->{'get' . ucfirst($type)}();
foreach ($links as $index => $link) {
// link is self.version, but must be replacing also the replaced version
if ('self.version' === $link->getPrettyConstraint()) {
$links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
}
}
$this->$type = $links;
}
// duplicate self.version provides
foreach (array('conflicts', 'provides', 'replaces') as $type) {
$links = $aliasOf->{'get'.ucfirst($type)}();
$newLinks = array();
foreach ($links as $link) {
// link is self.version, but must be replacing also the replaced version
if ('self.version' === $link->getPrettyConstraint()) {
$newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
}
}
$this->$type = array_merge($links, $newLinks);
$this->$type = $this->replaceSelfVersionDependencies($links, $type);
}
}
/**
* @return PackageInterface
*/
public function getAliasOf()
{
return $this->aliasOf;
@ -177,6 +161,22 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
return $this->rootPackageAlias;
}
/**
* @param array $links
* @param string $linkDescription
* @internal param string $prettyVersion
* @return array
*/
protected function replaceSelfVersionDependencies(array $links, $linkDescription = 'relates to')
{
foreach ($links as $index => $link) {
if ('self.version' === $link->getPrettyConstraint()) {
$links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $linkDescription, $this->prettyVersion);
}
}
return $links;
}
/***************************************
* Wrappers around the aliased package *
***************************************/

View File

@ -63,18 +63,24 @@ class RootAliasPackage extends AliasPackage implements RootPackageInterface
}
/**
* {@inheritDoc}
* @param array $require
* @return mixed
*/
public function setRequires(array $require)
{
$this->requires = $this->replaceSelfVersionDependencies($require, 'requires');
return $this->aliasOf->setRequires($require);
}
/**
* {@inheritDoc}
* @param array $devRequire
* @return mixed
*/
public function setDevRequires(array $devRequire)
{
$this->devRequires = $this->replaceSelfVersionDependencies($devRequire, 'devRequires');
return $this->aliasOf->setDevRequires($devRequire);
}