AliasPackage.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Package;
  12. use Composer\Package\LinkConstraint\LinkConstraintInterface;
  13. use Composer\Package\LinkConstraint\VersionConstraint;
  14. use Composer\Repository\RepositoryInterface;
  15. use Composer\Repository\PlatformRepository;
  16. use Composer\Package\Version\VersionParser;
  17. /**
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class AliasPackage extends BasePackage
  21. {
  22. protected $version;
  23. protected $prettyVersion;
  24. protected $dev;
  25. protected $aliasOf;
  26. protected $rootPackageAlias = false;
  27. protected $requires;
  28. protected $conflicts;
  29. protected $provides;
  30. protected $replaces;
  31. protected $recommends;
  32. protected $suggests;
  33. /**
  34. * All descendants' constructors should call this parent constructor
  35. *
  36. * @param PackageInterface $aliasOf The package this package is an alias of
  37. * @param string $version The version the alias must report
  38. * @param string $prettyVersion The alias's non-normalized version
  39. */
  40. public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
  41. {
  42. parent::__construct($aliasOf->getName());
  43. $this->version = $version;
  44. $this->prettyVersion = $prettyVersion;
  45. $this->aliasOf = $aliasOf;
  46. $this->dev = VersionParser::isDev($version);
  47. // replace self.version dependencies
  48. foreach (array('requires', 'devRequires') as $type) {
  49. $links = $aliasOf->{'get'.ucfirst($type)}();
  50. foreach ($links as $index => $link) {
  51. // link is self.version, but must be replacing also the replaced version
  52. if ('self.version' === $link->getPrettyConstraint()) {
  53. $links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $this->version);
  54. }
  55. }
  56. $this->$type = $links;
  57. }
  58. // duplicate self.version provides
  59. foreach (array('conflicts', 'provides', 'replaces') as $type) {
  60. $links = $aliasOf->{'get'.ucfirst($type)}();
  61. $newLinks = array();
  62. foreach ($links as $link) {
  63. // link is self.version, but must be replacing also the replaced version
  64. if ('self.version' === $link->getPrettyConstraint()) {
  65. $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $this->version);
  66. }
  67. }
  68. $this->$type = array_merge($links, $newLinks);
  69. }
  70. }
  71. public function getAliasOf()
  72. {
  73. return $this->aliasOf;
  74. }
  75. /**
  76. * {@inheritDoc}
  77. */
  78. public function getVersion()
  79. {
  80. return $this->version;
  81. }
  82. /**
  83. * {@inheritDoc}
  84. */
  85. public function getPrettyVersion()
  86. {
  87. return $this->prettyVersion;
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public function isDev()
  93. {
  94. return $this->dev;
  95. }
  96. /**
  97. * {@inheritDoc}
  98. */
  99. public function getRequires()
  100. {
  101. return $this->requires;
  102. }
  103. /**
  104. * {@inheritDoc}
  105. */
  106. public function getConflicts()
  107. {
  108. return $this->conflicts;
  109. }
  110. /**
  111. * {@inheritDoc}
  112. */
  113. public function getProvides()
  114. {
  115. return $this->provides;
  116. }
  117. /**
  118. * {@inheritDoc}
  119. */
  120. public function getReplaces()
  121. {
  122. return $this->replaces;
  123. }
  124. /**
  125. * {@inheritDoc}
  126. */
  127. public function getDevRequires()
  128. {
  129. return $this->devRequires;
  130. }
  131. /**
  132. * Stores whether this is an alias created by an aliasing in the requirements of the root package or not
  133. *
  134. * Use by the policy for sorting manually aliased packages first, see #576
  135. *
  136. * @param Boolean $value
  137. */
  138. public function setRootPackageAlias($value)
  139. {
  140. return $this->rootPackageAlias = $value;
  141. }
  142. /**
  143. * @see setRootPackageAlias
  144. * @return Boolean
  145. */
  146. public function isRootPackageAlias()
  147. {
  148. return $this->rootPackageAlias;
  149. }
  150. /**
  151. * {@inheritDoc}
  152. */
  153. public function getAlias()
  154. {
  155. return '';
  156. }
  157. /**
  158. * {@inheritDoc}
  159. */
  160. public function getPrettyAlias()
  161. {
  162. return '';
  163. }
  164. /***************************************
  165. * Wrappers around the aliased package *
  166. ***************************************/
  167. public function getType()
  168. {
  169. return $this->aliasOf->getType();
  170. }
  171. public function getTargetDir()
  172. {
  173. return $this->aliasOf->getTargetDir();
  174. }
  175. public function getExtra()
  176. {
  177. return $this->aliasOf->getExtra();
  178. }
  179. public function setInstallationSource($type)
  180. {
  181. $this->aliasOf->setInstallationSource($type);
  182. }
  183. public function getInstallationSource()
  184. {
  185. return $this->aliasOf->getInstallationSource();
  186. }
  187. public function getSourceType()
  188. {
  189. return $this->aliasOf->getSourceType();
  190. }
  191. public function getSourceUrl()
  192. {
  193. return $this->aliasOf->getSourceUrl();
  194. }
  195. public function getSourceReference()
  196. {
  197. return $this->aliasOf->getSourceReference();
  198. }
  199. public function setSourceReference($reference)
  200. {
  201. return $this->aliasOf->setSourceReference($reference);
  202. }
  203. public function getDistType()
  204. {
  205. return $this->aliasOf->getDistType();
  206. }
  207. public function getDistUrl()
  208. {
  209. return $this->aliasOf->getDistUrl();
  210. }
  211. public function getDistReference()
  212. {
  213. return $this->aliasOf->getDistReference();
  214. }
  215. public function getDistSha1Checksum()
  216. {
  217. return $this->aliasOf->getDistSha1Checksum();
  218. }
  219. public function getScripts()
  220. {
  221. return $this->aliasOf->getScripts();
  222. }
  223. public function setAliases(array $aliases)
  224. {
  225. return $this->aliasOf->setAliases($aliases);
  226. }
  227. public function getAliases()
  228. {
  229. return $this->aliasOf->getAliases();
  230. }
  231. public function getLicense()
  232. {
  233. return $this->aliasOf->getLicense();
  234. }
  235. public function getAutoload()
  236. {
  237. return $this->aliasOf->getAutoload();
  238. }
  239. public function getIncludePaths()
  240. {
  241. return $this->aliasOf->getIncludePaths();
  242. }
  243. public function getRepositories()
  244. {
  245. return $this->aliasOf->getRepositories();
  246. }
  247. public function getReleaseDate()
  248. {
  249. return $this->aliasOf->getReleaseDate();
  250. }
  251. public function getBinaries()
  252. {
  253. return $this->aliasOf->getBinaries();
  254. }
  255. public function getKeywords()
  256. {
  257. return $this->aliasOf->getKeywords();
  258. }
  259. public function getDescription()
  260. {
  261. return $this->aliasOf->getDescription();
  262. }
  263. public function getHomepage()
  264. {
  265. return $this->aliasOf->getHomepage();
  266. }
  267. public function getSuggests()
  268. {
  269. return $this->aliasOf->getSuggests();
  270. }
  271. public function getAuthors()
  272. {
  273. return $this->aliasOf->getAuthors();
  274. }
  275. public function __toString()
  276. {
  277. return parent::__toString().' (alias of '.$this->aliasOf->getVersion().')';
  278. }
  279. }