AliasPackage.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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\VersionConstraint;
  13. use Composer\Package\Version\VersionParser;
  14. /**
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. */
  17. class AliasPackage extends BasePackage implements CompletePackageInterface
  18. {
  19. protected $version;
  20. protected $prettyVersion;
  21. protected $dev;
  22. protected $aliasOf;
  23. protected $rootPackageAlias = false;
  24. protected $stability;
  25. protected $requires;
  26. protected $conflicts;
  27. protected $provides;
  28. protected $replaces;
  29. protected $recommends;
  30. protected $suggests;
  31. /**
  32. * All descendants' constructors should call this parent constructor
  33. *
  34. * @param PackageInterface $aliasOf The package this package is an alias of
  35. * @param string $version The version the alias must report
  36. * @param string $prettyVersion The alias's non-normalized version
  37. */
  38. public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
  39. {
  40. parent::__construct($aliasOf->getName());
  41. $this->version = $version;
  42. $this->prettyVersion = $prettyVersion;
  43. $this->aliasOf = $aliasOf;
  44. $this->stability = VersionParser::parseStability($version);
  45. $this->dev = $this->stability === 'dev';
  46. // replace self.version dependencies
  47. foreach (array('requires', 'devRequires') as $type) {
  48. $links = $aliasOf->{'get'.ucfirst($type)}();
  49. foreach ($links as $index => $link) {
  50. // link is self.version, but must be replacing also the replaced version
  51. if ('self.version' === $link->getPrettyConstraint()) {
  52. $links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
  53. }
  54. }
  55. $this->$type = $links;
  56. }
  57. // duplicate self.version provides
  58. foreach (array('conflicts', 'provides', 'replaces') as $type) {
  59. $links = $aliasOf->{'get'.ucfirst($type)}();
  60. $newLinks = array();
  61. foreach ($links as $link) {
  62. // link is self.version, but must be replacing also the replaced version
  63. if ('self.version' === $link->getPrettyConstraint()) {
  64. $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
  65. }
  66. }
  67. $this->$type = array_merge($links, $newLinks);
  68. }
  69. }
  70. public function getAliasOf()
  71. {
  72. return $this->aliasOf;
  73. }
  74. /**
  75. * {@inheritDoc}
  76. */
  77. public function getVersion()
  78. {
  79. return $this->version;
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public function getStability()
  85. {
  86. return $this->stability;
  87. }
  88. /**
  89. * {@inheritDoc}
  90. */
  91. public function getPrettyVersion()
  92. {
  93. return $this->prettyVersion;
  94. }
  95. /**
  96. * {@inheritDoc}
  97. */
  98. public function isDev()
  99. {
  100. return $this->dev;
  101. }
  102. /**
  103. * {@inheritDoc}
  104. */
  105. public function getRequires()
  106. {
  107. return $this->requires;
  108. }
  109. /**
  110. * {@inheritDoc}
  111. */
  112. public function getConflicts()
  113. {
  114. return $this->conflicts;
  115. }
  116. /**
  117. * {@inheritDoc}
  118. */
  119. public function getProvides()
  120. {
  121. return $this->provides;
  122. }
  123. /**
  124. * {@inheritDoc}
  125. */
  126. public function getReplaces()
  127. {
  128. return $this->replaces;
  129. }
  130. /**
  131. * {@inheritDoc}
  132. */
  133. public function getDevRequires()
  134. {
  135. return $this->devRequires;
  136. }
  137. /**
  138. * Stores whether this is an alias created by an aliasing in the requirements of the root package or not
  139. *
  140. * Use by the policy for sorting manually aliased packages first, see #576
  141. *
  142. * @param bool $value
  143. *
  144. * @return mixed
  145. */
  146. public function setRootPackageAlias($value)
  147. {
  148. return $this->rootPackageAlias = $value;
  149. }
  150. /**
  151. * @see setRootPackageAlias
  152. * @return bool
  153. */
  154. public function isRootPackageAlias()
  155. {
  156. return $this->rootPackageAlias;
  157. }
  158. /***************************************
  159. * Wrappers around the aliased package *
  160. ***************************************/
  161. public function getType()
  162. {
  163. return $this->aliasOf->getType();
  164. }
  165. public function getTargetDir()
  166. {
  167. return $this->aliasOf->getTargetDir();
  168. }
  169. public function getExtra()
  170. {
  171. return $this->aliasOf->getExtra();
  172. }
  173. public function setInstallationSource($type)
  174. {
  175. $this->aliasOf->setInstallationSource($type);
  176. }
  177. public function getInstallationSource()
  178. {
  179. return $this->aliasOf->getInstallationSource();
  180. }
  181. public function getSourceType()
  182. {
  183. return $this->aliasOf->getSourceType();
  184. }
  185. public function getSourceUrl()
  186. {
  187. return $this->aliasOf->getSourceUrl();
  188. }
  189. public function getSourceUrls()
  190. {
  191. return $this->aliasOf->getSourceUrls();
  192. }
  193. public function getSourceReference()
  194. {
  195. return $this->aliasOf->getSourceReference();
  196. }
  197. public function setSourceReference($reference)
  198. {
  199. return $this->aliasOf->setSourceReference($reference);
  200. }
  201. public function setSourceMirrors($mirrors)
  202. {
  203. return $this->aliasOf->setSourceMirrors($mirrors);
  204. }
  205. public function getSourceMirrors()
  206. {
  207. return $this->aliasOf->getSourceMirrors();
  208. }
  209. public function getDistType()
  210. {
  211. return $this->aliasOf->getDistType();
  212. }
  213. public function getDistUrl()
  214. {
  215. return $this->aliasOf->getDistUrl();
  216. }
  217. public function getDistUrls()
  218. {
  219. return $this->aliasOf->getDistUrls();
  220. }
  221. public function getDistReference()
  222. {
  223. return $this->aliasOf->getDistReference();
  224. }
  225. public function setDistReference($reference)
  226. {
  227. return $this->aliasOf->setDistReference($reference);
  228. }
  229. public function getDistSha1Checksum()
  230. {
  231. return $this->aliasOf->getDistSha1Checksum();
  232. }
  233. public function setTransportOptions(array $options)
  234. {
  235. return $this->aliasOf->setTransportOptions($options);
  236. }
  237. public function getTransportOptions()
  238. {
  239. return $this->aliasOf->getTransportOptions();
  240. }
  241. public function setDistMirrors($mirrors)
  242. {
  243. return $this->aliasOf->setDistMirrors($mirrors);
  244. }
  245. public function getDistMirrors()
  246. {
  247. return $this->aliasOf->getDistMirrors();
  248. }
  249. public function getScripts()
  250. {
  251. return $this->aliasOf->getScripts();
  252. }
  253. public function getLicense()
  254. {
  255. return $this->aliasOf->getLicense();
  256. }
  257. public function getAutoload()
  258. {
  259. return $this->aliasOf->getAutoload();
  260. }
  261. public function getDevAutoload()
  262. {
  263. return $this->aliasOf->getDevAutoload();
  264. }
  265. public function getIncludePaths()
  266. {
  267. return $this->aliasOf->getIncludePaths();
  268. }
  269. public function getRepositories()
  270. {
  271. return $this->aliasOf->getRepositories();
  272. }
  273. public function getReleaseDate()
  274. {
  275. return $this->aliasOf->getReleaseDate();
  276. }
  277. public function getBinaries()
  278. {
  279. return $this->aliasOf->getBinaries();
  280. }
  281. public function getKeywords()
  282. {
  283. return $this->aliasOf->getKeywords();
  284. }
  285. public function getDescription()
  286. {
  287. return $this->aliasOf->getDescription();
  288. }
  289. public function getHomepage()
  290. {
  291. return $this->aliasOf->getHomepage();
  292. }
  293. public function getSuggests()
  294. {
  295. return $this->aliasOf->getSuggests();
  296. }
  297. public function getAuthors()
  298. {
  299. return $this->aliasOf->getAuthors();
  300. }
  301. public function getSupport()
  302. {
  303. return $this->aliasOf->getSupport();
  304. }
  305. public function getNotificationUrl()
  306. {
  307. return $this->aliasOf->getNotificationUrl();
  308. }
  309. public function getArchiveExcludes()
  310. {
  311. return $this->aliasOf->getArchiveExcludes();
  312. }
  313. public function __toString()
  314. {
  315. return parent::__toString().' (alias of '.$this->aliasOf->getVersion().')';
  316. }
  317. }