Package.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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\Version\VersionParser;
  13. /**
  14. * Core package definitions that are needed to resolve dependencies and install packages
  15. *
  16. * @author Nils Adermann <naderman@naderman.de>
  17. */
  18. class Package extends BasePackage
  19. {
  20. protected $type;
  21. protected $targetDir;
  22. protected $installationSource;
  23. protected $sourceType;
  24. protected $sourceUrl;
  25. protected $sourceReference;
  26. protected $distType;
  27. protected $distUrl;
  28. protected $distReference;
  29. protected $distSha1Checksum;
  30. protected $version;
  31. protected $prettyVersion;
  32. protected $releaseDate;
  33. protected $extra = array();
  34. protected $binaries = array();
  35. protected $dev;
  36. protected $stability;
  37. protected $notificationUrl;
  38. protected $requires = array();
  39. protected $conflicts = array();
  40. protected $provides = array();
  41. protected $replaces = array();
  42. protected $devRequires = array();
  43. protected $suggests = array();
  44. protected $autoload = array();
  45. protected $includePaths = array();
  46. protected $archiveExcludes = array();
  47. /**
  48. * Creates a new in memory package.
  49. *
  50. * @param string $name The package's name
  51. * @param string $version The package's version
  52. * @param string $prettyVersion The package's non-normalized version
  53. */
  54. public function __construct($name, $version, $prettyVersion)
  55. {
  56. parent::__construct($name);
  57. $this->version = $version;
  58. $this->prettyVersion = $prettyVersion;
  59. $this->stability = VersionParser::parseStability($version);
  60. $this->dev = $this->stability === 'dev';
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function isDev()
  66. {
  67. return $this->dev;
  68. }
  69. /**
  70. * @param string $type
  71. */
  72. public function setType($type)
  73. {
  74. $this->type = $type;
  75. }
  76. /**
  77. * {@inheritDoc}
  78. */
  79. public function getType()
  80. {
  81. return $this->type ?: 'library';
  82. }
  83. /**
  84. * {@inheritDoc}
  85. */
  86. public function getStability()
  87. {
  88. return $this->stability;
  89. }
  90. /**
  91. * @param string $targetDir
  92. */
  93. public function setTargetDir($targetDir)
  94. {
  95. $this->targetDir = $targetDir;
  96. }
  97. /**
  98. * {@inheritDoc}
  99. */
  100. public function getTargetDir()
  101. {
  102. if (null === $this->targetDir) {
  103. return;
  104. }
  105. return ltrim(preg_replace('{ (?:^|[\\\\/]+) \.\.? (?:[\\\\/]+|$) (?:\.\.? (?:[\\\\/]+|$) )*}x', '/', $this->targetDir), '/');
  106. }
  107. /**
  108. * @param array $extra
  109. */
  110. public function setExtra(array $extra)
  111. {
  112. $this->extra = $extra;
  113. }
  114. /**
  115. * {@inheritDoc}
  116. */
  117. public function getExtra()
  118. {
  119. return $this->extra;
  120. }
  121. /**
  122. * @param array $binaries
  123. */
  124. public function setBinaries(array $binaries)
  125. {
  126. $this->binaries = $binaries;
  127. }
  128. /**
  129. * {@inheritDoc}
  130. */
  131. public function getBinaries()
  132. {
  133. return $this->binaries;
  134. }
  135. /**
  136. * {@inheritDoc}
  137. */
  138. public function setInstallationSource($type)
  139. {
  140. $this->installationSource = $type;
  141. }
  142. /**
  143. * {@inheritDoc}
  144. */
  145. public function getInstallationSource()
  146. {
  147. return $this->installationSource;
  148. }
  149. /**
  150. * @param string $type
  151. */
  152. public function setSourceType($type)
  153. {
  154. $this->sourceType = $type;
  155. }
  156. /**
  157. * {@inheritDoc}
  158. */
  159. public function getSourceType()
  160. {
  161. return $this->sourceType;
  162. }
  163. /**
  164. * @param string $url
  165. */
  166. public function setSourceUrl($url)
  167. {
  168. $this->sourceUrl = $url;
  169. }
  170. /**
  171. * {@inheritDoc}
  172. */
  173. public function getSourceUrl()
  174. {
  175. return $this->sourceUrl;
  176. }
  177. /**
  178. * @param string $reference
  179. */
  180. public function setSourceReference($reference)
  181. {
  182. $this->sourceReference = $reference;
  183. }
  184. /**
  185. * {@inheritDoc}
  186. */
  187. public function getSourceReference()
  188. {
  189. return $this->sourceReference;
  190. }
  191. /**
  192. * @param string $type
  193. */
  194. public function setDistType($type)
  195. {
  196. $this->distType = $type;
  197. }
  198. /**
  199. * {@inheritDoc}
  200. */
  201. public function getDistType()
  202. {
  203. return $this->distType;
  204. }
  205. /**
  206. * @param string $url
  207. */
  208. public function setDistUrl($url)
  209. {
  210. $this->distUrl = $url;
  211. }
  212. /**
  213. * {@inheritDoc}
  214. */
  215. public function getDistUrl()
  216. {
  217. return $this->distUrl;
  218. }
  219. /**
  220. * @param string $reference
  221. */
  222. public function setDistReference($reference)
  223. {
  224. $this->distReference = $reference;
  225. }
  226. /**
  227. * {@inheritDoc}
  228. */
  229. public function getDistReference()
  230. {
  231. return $this->distReference;
  232. }
  233. /**
  234. * @param string $sha1checksum
  235. */
  236. public function setDistSha1Checksum($sha1checksum)
  237. {
  238. $this->distSha1Checksum = $sha1checksum;
  239. }
  240. /**
  241. * {@inheritDoc}
  242. */
  243. public function getDistSha1Checksum()
  244. {
  245. return $this->distSha1Checksum;
  246. }
  247. /**
  248. * {@inheritDoc}
  249. */
  250. public function getVersion()
  251. {
  252. return $this->version;
  253. }
  254. /**
  255. * {@inheritDoc}
  256. */
  257. public function getPrettyVersion()
  258. {
  259. return $this->prettyVersion;
  260. }
  261. /**
  262. * Set the releaseDate
  263. *
  264. * @param \DateTime $releaseDate
  265. */
  266. public function setReleaseDate(\DateTime $releaseDate)
  267. {
  268. $this->releaseDate = $releaseDate;
  269. }
  270. /**
  271. * {@inheritDoc}
  272. */
  273. public function getReleaseDate()
  274. {
  275. return $this->releaseDate;
  276. }
  277. /**
  278. * Set the required packages
  279. *
  280. * @param array $requires A set of package links
  281. */
  282. public function setRequires(array $requires)
  283. {
  284. $this->requires = $requires;
  285. }
  286. /**
  287. * {@inheritDoc}
  288. */
  289. public function getRequires()
  290. {
  291. return $this->requires;
  292. }
  293. /**
  294. * Set the conflicting packages
  295. *
  296. * @param array $conflicts A set of package links
  297. */
  298. public function setConflicts(array $conflicts)
  299. {
  300. $this->conflicts = $conflicts;
  301. }
  302. /**
  303. * {@inheritDoc}
  304. */
  305. public function getConflicts()
  306. {
  307. return $this->conflicts;
  308. }
  309. /**
  310. * Set the provided virtual packages
  311. *
  312. * @param array $provides A set of package links
  313. */
  314. public function setProvides(array $provides)
  315. {
  316. $this->provides = $provides;
  317. }
  318. /**
  319. * {@inheritDoc}
  320. */
  321. public function getProvides()
  322. {
  323. return $this->provides;
  324. }
  325. /**
  326. * Set the packages this one replaces
  327. *
  328. * @param array $replaces A set of package links
  329. */
  330. public function setReplaces(array $replaces)
  331. {
  332. $this->replaces = $replaces;
  333. }
  334. /**
  335. * {@inheritDoc}
  336. */
  337. public function getReplaces()
  338. {
  339. return $this->replaces;
  340. }
  341. /**
  342. * Set the recommended packages
  343. *
  344. * @param array $devRequires A set of package links
  345. */
  346. public function setDevRequires(array $devRequires)
  347. {
  348. $this->devRequires = $devRequires;
  349. }
  350. /**
  351. * {@inheritDoc}
  352. */
  353. public function getDevRequires()
  354. {
  355. return $this->devRequires;
  356. }
  357. /**
  358. * Set the suggested packages
  359. *
  360. * @param array $suggests A set of package names/comments
  361. */
  362. public function setSuggests(array $suggests)
  363. {
  364. $this->suggests = $suggests;
  365. }
  366. /**
  367. * {@inheritDoc}
  368. */
  369. public function getSuggests()
  370. {
  371. return $this->suggests;
  372. }
  373. /**
  374. * Set the autoload mapping
  375. *
  376. * @param array $autoload Mapping of autoloading rules
  377. */
  378. public function setAutoload(array $autoload)
  379. {
  380. $this->autoload = $autoload;
  381. }
  382. /**
  383. * {@inheritDoc}
  384. */
  385. public function getAutoload()
  386. {
  387. return $this->autoload;
  388. }
  389. /**
  390. * Sets the list of paths added to PHP's include path.
  391. *
  392. * @param array $includePaths List of directories.
  393. */
  394. public function setIncludePaths(array $includePaths)
  395. {
  396. $this->includePaths = $includePaths;
  397. }
  398. /**
  399. * {@inheritDoc}
  400. */
  401. public function getIncludePaths()
  402. {
  403. return $this->includePaths;
  404. }
  405. /**
  406. * Sets the notification URL
  407. *
  408. * @param string $notificationUrl
  409. */
  410. public function setNotificationUrl($notificationUrl)
  411. {
  412. $this->notificationUrl = $notificationUrl;
  413. }
  414. /**
  415. * {@inheritDoc}
  416. */
  417. public function getNotificationUrl()
  418. {
  419. return $this->notificationUrl;
  420. }
  421. /**
  422. * Sets a list of patterns to be excluded from archives
  423. *
  424. * @param array $excludes
  425. */
  426. public function setArchiveExcludes(array $excludes)
  427. {
  428. $this->archiveExcludes = $excludes;
  429. }
  430. /**
  431. * {@inheritDoc}
  432. */
  433. public function getArchiveExcludes()
  434. {
  435. return $this->archiveExcludes;
  436. }
  437. }