AliasPackage.php 8.8 KB

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