From b02bdb4c7ae104a844b415a8b83f52592e4362d2 Mon Sep 17 00:00:00 2001 From: Vadim Tyukov Date: Tue, 10 Dec 2013 11:49:54 +0200 Subject: [PATCH] [alias] RootAliasPackage manages the requirements correctly --- src/Composer/Package/AliasPackage.php | 46 +++++++++++------------ src/Composer/Package/RootAliasPackage.php | 10 ++++- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 3ab9c944d..8c47e685e 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -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) { - $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); + foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) { + $links = $aliasOf->{'get' . ucfirst($type)}(); + $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 * ***************************************/ diff --git a/src/Composer/Package/RootAliasPackage.php b/src/Composer/Package/RootAliasPackage.php index a16e0e914..471d8b3df 100644 --- a/src/Composer/Package/RootAliasPackage.php +++ b/src/Composer/Package/RootAliasPackage.php @@ -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); }