AliasPackage.php 9.1 KB

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