Package.php 10 KB

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