AliasPackage.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. /**
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class AliasPackage extends BasePackage
  20. {
  21. protected $version;
  22. protected $prettyVersion;
  23. protected $dev;
  24. protected $aliasOf;
  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($aliasOf, $version, $prettyVersion)
  39. {
  40. parent::__construct($aliasOf->getName());
  41. $this->version = $version;
  42. $this->prettyVersion = $prettyVersion;
  43. $this->aliasOf = $aliasOf;
  44. $this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4);
  45. foreach (self::$supportedLinkTypes as $type => $description) {
  46. $links = $aliasOf->{'get'.ucfirst($description)}();
  47. $newLinks = array();
  48. foreach ($links as $link) {
  49. // link is self.version, but must be replacing also the replaced version
  50. if ('self.version' === $link->getPrettyConstraint()) {
  51. $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $description, $this->version);
  52. }
  53. }
  54. $this->$description = array_merge($links, $newLinks);
  55. }
  56. }
  57. public function getAliasOf()
  58. {
  59. return $this->aliasOf;
  60. }
  61. /**
  62. * {@inheritDoc}
  63. */
  64. public function getVersion()
  65. {
  66. return $this->version;
  67. }
  68. /**
  69. * {@inheritDoc}
  70. */
  71. public function getPrettyVersion()
  72. {
  73. return $this->prettyVersion;
  74. }
  75. /**
  76. * {@inheritDoc}
  77. */
  78. public function isDev()
  79. {
  80. return $this->dev;
  81. }
  82. /**
  83. * {@inheritDoc}
  84. */
  85. public function getRequires()
  86. {
  87. return $this->requires;
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public function getConflicts()
  93. {
  94. return $this->conflicts;
  95. }
  96. /**
  97. * {@inheritDoc}
  98. */
  99. public function getProvides()
  100. {
  101. return $this->provides;
  102. }
  103. /**
  104. * {@inheritDoc}
  105. */
  106. public function getReplaces()
  107. {
  108. return $this->replaces;
  109. }
  110. /**
  111. * {@inheritDoc}
  112. */
  113. public function getRecommends()
  114. {
  115. return $this->recommends;
  116. }
  117. /**
  118. * {@inheritDoc}
  119. */
  120. public function getSuggests()
  121. {
  122. return $this->suggests;
  123. }
  124. /**
  125. * {@inheritDoc}
  126. */
  127. public function getAlias()
  128. {
  129. return '';
  130. }
  131. /**
  132. * {@inheritDoc}
  133. */
  134. public function getPrettyAlias()
  135. {
  136. return '';
  137. }
  138. /***************************************
  139. * Wrappers around the aliased package *
  140. ***************************************/
  141. public function getType()
  142. {
  143. return $this->aliasOf->getType();
  144. }
  145. public function getTargetDir()
  146. {
  147. return $this->aliasOf->getTargetDir();
  148. }
  149. public function getExtra()
  150. {
  151. return $this->aliasOf->getExtra();
  152. }
  153. public function setInstallationSource($type)
  154. {
  155. $this->aliasOf->setInstallationSource($type);
  156. }
  157. public function getInstallationSource()
  158. {
  159. return $this->aliasOf->getInstallationSource();
  160. }
  161. public function getSourceType()
  162. {
  163. return $this->aliasOf->getSourceType();
  164. }
  165. public function getSourceUrl()
  166. {
  167. return $this->aliasOf->getSourceUrl();
  168. }
  169. public function getSourceReference()
  170. {
  171. return $this->aliasOf->getSourceReference();
  172. }
  173. public function setSourceReference($reference)
  174. {
  175. return $this->aliasOf->setSourceReference($reference);
  176. }
  177. public function getDistType()
  178. {
  179. return $this->aliasOf->getDistType();
  180. }
  181. public function getDistUrl()
  182. {
  183. return $this->aliasOf->getDistUrl();
  184. }
  185. public function getDistReference()
  186. {
  187. return $this->aliasOf->getDistReference();
  188. }
  189. public function getDistSha1Checksum()
  190. {
  191. return $this->aliasOf->getDistSha1Checksum();
  192. }
  193. public function getScripts()
  194. {
  195. return $this->aliasOf->getScripts();
  196. }
  197. public function getLicense()
  198. {
  199. return $this->aliasOf->getLicense();
  200. }
  201. public function getAutoload()
  202. {
  203. return $this->aliasOf->getAutoload();
  204. }
  205. public function getRepositories()
  206. {
  207. return $this->aliasOf->getRepositories();
  208. }
  209. public function getReleaseDate()
  210. {
  211. return $this->aliasOf->getReleaseDate();
  212. }
  213. public function getBinaries()
  214. {
  215. return $this->aliasOf->getBinaries();
  216. }
  217. public function getKeywords()
  218. {
  219. return $this->aliasOf->getKeywords();
  220. }
  221. public function getDescription()
  222. {
  223. return $this->aliasOf->getDescription();
  224. }
  225. public function getHomepage()
  226. {
  227. return $this->aliasOf->getHomepage();
  228. }
  229. public function getAuthors()
  230. {
  231. return $this->aliasOf->getAuthors();
  232. }
  233. public function __toString()
  234. {
  235. return parent::__toString().' (alias of '.$this->aliasOf->getVersion().')';
  236. }
  237. }