Package.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  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 Packagist\WebBundle\Entity;
  12. use Composer\Factory;
  13. use Composer\IO\NullIO;
  14. use Composer\Repository\VcsRepository;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  19. use Composer\Repository\Vcs\GitHubDriver;
  20. /**
  21. * @ORM\Entity(repositoryClass="Packagist\WebBundle\Entity\PackageRepository")
  22. * @ORM\Table(
  23. * name="package",
  24. * uniqueConstraints={@ORM\UniqueConstraint(name="package_name_idx", columns={"name"})},
  25. * indexes={
  26. * @ORM\Index(name="indexed_idx",columns={"indexedAt"}),
  27. * @ORM\Index(name="crawled_idx",columns={"crawledAt"}),
  28. * @ORM\Index(name="dumped_idx",columns={"dumpedAt"})
  29. * }
  30. * )
  31. * @Assert\Callback(callback="isPackageUnique")
  32. * @Assert\Callback(callback="isVendorWritable")
  33. * @Assert\Callback(callback="isRepositoryValid", groups={"Update", "Default"})
  34. * @author Jordi Boggiano <j.boggiano@seld.be>
  35. */
  36. class Package
  37. {
  38. /**
  39. * @ORM\Id
  40. * @ORM\Column(type="integer")
  41. * @ORM\GeneratedValue(strategy="AUTO")
  42. */
  43. private $id;
  44. /**
  45. * Unique package name
  46. *
  47. * @ORM\Column(length=191)
  48. */
  49. private $name;
  50. /**
  51. * @ORM\Column(nullable=true)
  52. */
  53. private $type;
  54. /**
  55. * @ORM\Column(type="text", nullable=true)
  56. */
  57. private $description;
  58. /**
  59. * @ORM\Column(type="string", nullable=true)
  60. */
  61. private $language;
  62. /**
  63. * @ORM\Column(type="text", nullable=true)
  64. */
  65. private $readme;
  66. /**
  67. * @ORM\Column(type="integer", nullable=true, name="github_stars")
  68. */
  69. private $gitHubStars;
  70. /**
  71. * @ORM\Column(type="integer", nullable=true, name="github_watches")
  72. */
  73. private $gitHubWatches;
  74. /**
  75. * @ORM\Column(type="integer", nullable=true, name="github_forks")
  76. */
  77. private $gitHubForks;
  78. /**
  79. * @ORM\Column(type="integer", nullable=true, name="github_open_issues")
  80. */
  81. private $gitHubOpenIssues;
  82. /**
  83. * @ORM\OneToMany(targetEntity="Packagist\WebBundle\Entity\Version", mappedBy="package")
  84. */
  85. private $versions;
  86. /**
  87. * @ORM\ManyToMany(targetEntity="User", inversedBy="packages")
  88. * @ORM\JoinTable(name="maintainers_packages")
  89. */
  90. private $maintainers;
  91. /**
  92. * @ORM\Column()
  93. * @Assert\NotBlank(groups={"Update", "Default"})
  94. */
  95. private $repository;
  96. // dist-tags / rel or runtime?
  97. /**
  98. * @ORM\Column(type="datetime")
  99. */
  100. private $createdAt;
  101. /**
  102. * @ORM\Column(type="datetime", nullable=true)
  103. */
  104. private $updatedAt;
  105. /**
  106. * @ORM\Column(type="datetime", nullable=true)
  107. */
  108. private $crawledAt;
  109. /**
  110. * @ORM\Column(type="datetime", nullable=true)
  111. */
  112. private $indexedAt;
  113. /**
  114. * @ORM\Column(type="datetime", nullable=true)
  115. */
  116. private $dumpedAt;
  117. /**
  118. * @ORM\OneToMany(targetEntity="Packagist\WebBundle\Entity\Download", mappedBy="package")
  119. */
  120. private $downloads;
  121. /**
  122. * @ORM\Column(type="boolean")
  123. */
  124. private $autoUpdated = false;
  125. /**
  126. * @var bool
  127. * @ORM\Column(type="boolean")
  128. */
  129. private $abandoned = false;
  130. /**
  131. * @var string
  132. * @ORM\Column(type="string", length=255, nullable=true)
  133. */
  134. private $replacementPackage;
  135. /**
  136. * @ORM\Column(type="boolean", options={"default"=false})
  137. */
  138. private $updateFailureNotified = false;
  139. private $entityRepository;
  140. private $router;
  141. /**
  142. * @var \Composer\Repository\Vcs\VcsDriverInterface
  143. */
  144. private $vcsDriver = true;
  145. private $vcsDriverError;
  146. /**
  147. * @var array lookup table for versions
  148. */
  149. private $cachedVersions;
  150. public function __construct()
  151. {
  152. $this->versions = new ArrayCollection();
  153. $this->createdAt = new \DateTime;
  154. }
  155. public function toArray(VersionRepository $versionRepo)
  156. {
  157. $versions = array();
  158. $versionIds = [];
  159. $this->versions = $versionRepo->refreshVersions($this->getVersions());
  160. foreach ($this->getVersions() as $version) {
  161. $versionIds[] = $version->getId();
  162. }
  163. $versionData = $versionRepo->getVersionData($versionIds);
  164. foreach ($this->getVersions() as $version) {
  165. /** @var $version Version */
  166. $versions[$version->getVersion()] = $version->toArray($versionData);
  167. }
  168. $maintainers = array();
  169. foreach ($this->getMaintainers() as $maintainer) {
  170. /** @var $maintainer User */
  171. $maintainers[] = $maintainer->toArray();
  172. }
  173. $data = array(
  174. 'name' => $this->getName(),
  175. 'description' => $this->getDescription(),
  176. 'time' => $this->getCreatedAt()->format('c'),
  177. 'maintainers' => $maintainers,
  178. 'versions' => $versions,
  179. 'type' => $this->getType(),
  180. 'repository' => $this->getRepository(),
  181. 'github_stars' => $this->getGitHubStars(),
  182. 'github_watchers' => $this->getGitHubWatches(),
  183. 'github_forks' => $this->getGitHubForks(),
  184. 'github_open_issues' => $this->getGitHubOpenIssues(),
  185. 'language' => $this->getLanguage(),
  186. );
  187. if ($this->isAbandoned()) {
  188. $data['abandoned'] = $this->getReplacementPackage() ?: true;
  189. }
  190. return $data;
  191. }
  192. public function isRepositoryValid(ExecutionContextInterface $context)
  193. {
  194. // vcs driver was not nulled which means the repository was not set/modified and is still valid
  195. if (true === $this->vcsDriver && null !== $this->getName()) {
  196. return;
  197. }
  198. $property = 'repository';
  199. $driver = $this->vcsDriver;
  200. if (!is_object($driver)) {
  201. if (preg_match('{^http://}', $this->repository)) {
  202. $context->buildViolation('Non-secure HTTP URLs are not supported, make sure you use an HTTPS or SSH URL')
  203. ->atPath($property)
  204. ->addViolation()
  205. ;
  206. } elseif (preg_match('{https?://.+@}', $this->repository)) {
  207. $context->buildViolation('URLs with user@host are not supported, use a read-only public URL')
  208. ->atPath($property)
  209. ->addViolation()
  210. ;
  211. } elseif (is_string($this->vcsDriverError)) {
  212. $context->buildViolation('Uncaught Exception: '.htmlentities($this->vcsDriverError, ENT_COMPAT, 'utf-8'))
  213. ->atPath($property)
  214. ->addViolation()
  215. ;
  216. } else {
  217. $context->buildViolation('No valid/supported repository was found at the given URL')
  218. ->atPath($property)
  219. ->addViolation()
  220. ;
  221. }
  222. return;
  223. }
  224. try {
  225. $information = $driver->getComposerInformation($driver->getRootIdentifier());
  226. if (false === $information) {
  227. $context->buildViolation('No composer.json was found in the '.$driver->getRootIdentifier().' branch.')
  228. ->atPath($property)
  229. ->addViolation()
  230. ;
  231. return;
  232. }
  233. if (empty($information['name'])) {
  234. $context->buildViolation('The package name was not found in the composer.json, make sure there is a name present.')
  235. ->atPath($property)
  236. ->addViolation()
  237. ;
  238. return;
  239. }
  240. if (!preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*$}i', $information['name'])) {
  241. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*".')
  242. ->atPath($property)
  243. ->addViolation()
  244. ;
  245. return;
  246. }
  247. if (preg_match('{(free.*watch|watch.*free|movie.*free|free.*movie|watch.*movie|watch.*full|generate.*resource|generate.*unlimited|hack.*coin|coin.*hack|v[.-]?bucks|(fortnite|pubg).*free|hack.*cheat|cheat.*hack|putlocker)}i', $information['name'])) {
  248. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is blocked, if you think this is a mistake please get in touch with us.')
  249. ->atPath($property)
  250. ->addViolation()
  251. ;
  252. return;
  253. }
  254. $reservedNames = ['nul', 'con', 'prn', 'aux', 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'];
  255. $bits = explode('/', strtolower($information['name']));
  256. if (in_array($bits[0], $reservedNames, true) || in_array($bits[1], $reservedNames, true)) {
  257. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is reserved, package and vendor names can not match any of: '.implode(', ', $reservedNames).'.')
  258. ->atPath($property)
  259. ->addViolation()
  260. ;
  261. return;
  262. }
  263. if (preg_match('{\.json$}', $information['name'])) {
  264. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, package names can not end in .json, consider renaming it or perhaps using a -json suffix instead.')
  265. ->atPath($property)
  266. ->addViolation()
  267. ;
  268. return;
  269. }
  270. if (preg_match('{[A-Z]}', $information['name'])) {
  271. $suggestName = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $information['name']);
  272. $suggestName = strtolower($suggestName);
  273. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, it should not contain uppercase characters. We suggest using '.$suggestName.' instead.')
  274. ->atPath($property)
  275. ->addViolation()
  276. ;
  277. return;
  278. }
  279. } catch (\Exception $e) {
  280. $context->buildViolation('We had problems parsing your composer.json file, the parser reports: '.htmlentities($e->getMessage(), ENT_COMPAT, 'utf-8'))
  281. ->atPath($property)
  282. ->addViolation()
  283. ;
  284. }
  285. if (null === $this->getName()) {
  286. $context->buildViolation('An unexpected error has made our parser fail to find a package name in your repository, if you think this is incorrect please try again')
  287. ->atPath($property)
  288. ->addViolation()
  289. ;
  290. }
  291. }
  292. public function setEntityRepository($repository)
  293. {
  294. $this->entityRepository = $repository;
  295. }
  296. public function setRouter($router)
  297. {
  298. $this->router = $router;
  299. }
  300. public function isPackageUnique(ExecutionContextInterface $context)
  301. {
  302. try {
  303. if ($this->entityRepository->findOneByName($this->name)) {
  304. $context->buildViolation('A package with the name <a href="'.$this->router->generate('view_package', array('name' => $this->name)).'">'.$this->name.'</a> already exists.')
  305. ->atPath('repository')
  306. ->addViolation()
  307. ;
  308. }
  309. } catch (\Doctrine\ORM\NoResultException $e) {}
  310. }
  311. public function isVendorWritable(ExecutionContextInterface $context)
  312. {
  313. try {
  314. $vendor = $this->getVendor();
  315. if ($vendor && $this->entityRepository->isVendorTaken($vendor, reset($this->maintainers))) {
  316. $context->buildViolation('The vendor is already taken by someone else. '
  317. . 'You may ask them to add your package and give you maintainership access. '
  318. . 'If they add you as a maintainer on any package in that vendor namespace, '
  319. . 'you will then be able to add new packages in that namespace. '
  320. . 'The packages already in that vendor namespace can be found at '
  321. . '<a href="'.$this->router->generate('view_vendor', array('vendor' => $vendor)).'">'.$vendor.'</a>')
  322. ->atPath('repository')
  323. ->addViolation()
  324. ;
  325. }
  326. } catch (\Doctrine\ORM\NoResultException $e) {}
  327. }
  328. /**
  329. * Get id
  330. *
  331. * @return string
  332. */
  333. public function getId()
  334. {
  335. return $this->id;
  336. }
  337. /**
  338. * Set name
  339. *
  340. * @param string $name
  341. */
  342. public function setName($name)
  343. {
  344. $this->name = $name;
  345. }
  346. /**
  347. * Get name
  348. *
  349. * @return string
  350. */
  351. public function getName()
  352. {
  353. return $this->name;
  354. }
  355. /**
  356. * Get vendor prefix
  357. *
  358. * @return string
  359. */
  360. public function getVendor()
  361. {
  362. return preg_replace('{/.*$}', '', $this->name);
  363. }
  364. /**
  365. * Get package name without vendor
  366. *
  367. * @return string
  368. */
  369. public function getPackageName()
  370. {
  371. return preg_replace('{^[^/]*/}', '', $this->name);
  372. }
  373. /**
  374. * Set description
  375. *
  376. * @param string $description
  377. */
  378. public function setDescription($description)
  379. {
  380. $this->description = $description;
  381. }
  382. /**
  383. * Get description
  384. *
  385. * @return string
  386. */
  387. public function getDescription()
  388. {
  389. return $this->description;
  390. }
  391. /**
  392. * Set language
  393. *
  394. * @param string $language
  395. */
  396. public function setLanguage($language)
  397. {
  398. $this->language = $language;
  399. }
  400. /**
  401. * Get language
  402. *
  403. * @return string
  404. */
  405. public function getLanguage()
  406. {
  407. return $this->language;
  408. }
  409. /**
  410. * Set readme
  411. *
  412. * @param string $readme
  413. */
  414. public function setReadme($readme)
  415. {
  416. $this->readme = $readme;
  417. }
  418. /**
  419. * Get readme
  420. *
  421. * @return string
  422. */
  423. public function getReadme()
  424. {
  425. return $this->readme;
  426. }
  427. /**
  428. * @param int $val
  429. */
  430. public function setGitHubStars($val)
  431. {
  432. $this->gitHubStars = $val;
  433. }
  434. /**
  435. * @return int
  436. */
  437. public function getGitHubStars()
  438. {
  439. return $this->gitHubStars;
  440. }
  441. /**
  442. * @param int $val
  443. */
  444. public function setGitHubWatches($val)
  445. {
  446. $this->gitHubWatches = $val;
  447. }
  448. /**
  449. * @return int
  450. */
  451. public function getGitHubWatches()
  452. {
  453. return $this->gitHubWatches;
  454. }
  455. /**
  456. * @param int $val
  457. */
  458. public function setGitHubForks($val)
  459. {
  460. $this->gitHubForks = $val;
  461. }
  462. /**
  463. * @return int
  464. */
  465. public function getGitHubForks()
  466. {
  467. return $this->gitHubForks;
  468. }
  469. /**
  470. * @param int $val
  471. */
  472. public function setGitHubOpenIssues($val)
  473. {
  474. $this->gitHubOpenIssues = $val;
  475. }
  476. /**
  477. * @return int
  478. */
  479. public function getGitHubOpenIssues()
  480. {
  481. return $this->gitHubOpenIssues;
  482. }
  483. /**
  484. * Set createdAt
  485. *
  486. * @param \DateTime $createdAt
  487. */
  488. public function setCreatedAt($createdAt)
  489. {
  490. $this->createdAt = $createdAt;
  491. }
  492. /**
  493. * Get createdAt
  494. *
  495. * @return \DateTime
  496. */
  497. public function getCreatedAt()
  498. {
  499. return $this->createdAt;
  500. }
  501. /**
  502. * Set repository
  503. *
  504. * @param string $repository
  505. */
  506. public function setRepository($repoUrl)
  507. {
  508. $this->vcsDriver = null;
  509. // prevent local filesystem URLs
  510. if (preg_match('{^(\.|[a-z]:|/)}i', $repoUrl)) {
  511. return;
  512. }
  513. $repoUrl = preg_replace('{^git@github.com:}i', 'https://github.com/', $repoUrl);
  514. $repoUrl = preg_replace('{^git://github.com/}i', 'https://github.com/', $repoUrl);
  515. $repoUrl = preg_replace('{^(https://github.com/.*?)\.git$}i', '$1', $repoUrl);
  516. // normalize protocol case
  517. $repoUrl = preg_replace_callback('{^(https?|git|svn)://}i', function ($match) { return strtolower($match[1]) . '://'; }, $repoUrl);
  518. $this->repository = $repoUrl;
  519. // avoid user@host URLs
  520. if (preg_match('{https?://.+@}', $repoUrl)) {
  521. return;
  522. }
  523. try {
  524. $io = new NullIO();
  525. $config = Factory::createConfig();
  526. $io->loadConfiguration($config);
  527. $repository = new VcsRepository(array('url' => $this->repository), $io, $config);
  528. $driver = $this->vcsDriver = $repository->getDriver();
  529. if (!$driver) {
  530. return;
  531. }
  532. $information = $driver->getComposerInformation($driver->getRootIdentifier());
  533. if (!isset($information['name'])) {
  534. return;
  535. }
  536. if (null === $this->getName()) {
  537. $this->setName($information['name']);
  538. }
  539. if ($driver instanceof GitHubDriver) {
  540. $this->repository = $driver->getRepositoryUrl();
  541. }
  542. } catch (\Exception $e) {
  543. $this->vcsDriverError = '['.get_class($e).'] '.$e->getMessage();
  544. }
  545. }
  546. /**
  547. * Get repository
  548. *
  549. * @return string $repository
  550. */
  551. public function getRepository()
  552. {
  553. return $this->repository;
  554. }
  555. /**
  556. * Get a user-browsable version of the repository URL
  557. *
  558. * @return string $repository
  559. */
  560. public function getBrowsableRepository()
  561. {
  562. if (preg_match('{(://|@)bitbucket.org[:/]}i', $this->repository)) {
  563. return preg_replace('{^(?:git@|https://|git://)bitbucket.org[:/](.+?)(?:\.git)?$}i', 'https://bitbucket.org/$1', $this->repository);
  564. }
  565. return preg_replace('{^(git://github.com/|git@github.com:)}', 'https://github.com/', $this->repository);
  566. }
  567. /**
  568. * Add versions
  569. *
  570. * @param Version $versions
  571. */
  572. public function addVersions(Version $versions)
  573. {
  574. $this->versions[] = $versions;
  575. }
  576. /**
  577. * Get versions
  578. *
  579. * @return \Doctrine\Common\Collections\Collection
  580. */
  581. public function getVersions()
  582. {
  583. return $this->versions;
  584. }
  585. public function getVersion($normalizedVersion)
  586. {
  587. if (null === $this->cachedVersions) {
  588. $this->cachedVersions = array();
  589. foreach ($this->getVersions() as $version) {
  590. $this->cachedVersions[strtolower($version->getNormalizedVersion())] = $version;
  591. }
  592. }
  593. if (isset($this->cachedVersions[strtolower($normalizedVersion)])) {
  594. return $this->cachedVersions[strtolower($normalizedVersion)];
  595. }
  596. }
  597. /**
  598. * Set updatedAt
  599. *
  600. * @param \DateTime $updatedAt
  601. */
  602. public function setUpdatedAt($updatedAt)
  603. {
  604. $this->updatedAt = $updatedAt;
  605. $this->setUpdateFailureNotified(false);
  606. }
  607. /**
  608. * Get updatedAt
  609. *
  610. * @return \DateTime
  611. */
  612. public function getUpdatedAt()
  613. {
  614. return $this->updatedAt;
  615. }
  616. /**
  617. * Set crawledAt
  618. *
  619. * @param \DateTime|null $crawledAt
  620. */
  621. public function setCrawledAt($crawledAt)
  622. {
  623. $this->crawledAt = $crawledAt;
  624. }
  625. /**
  626. * Get crawledAt
  627. *
  628. * @return \DateTime
  629. */
  630. public function getCrawledAt()
  631. {
  632. return $this->crawledAt;
  633. }
  634. /**
  635. * Set indexedAt
  636. *
  637. * @param \DateTime $indexedAt
  638. */
  639. public function setIndexedAt($indexedAt)
  640. {
  641. $this->indexedAt = $indexedAt;
  642. }
  643. /**
  644. * Get indexedAt
  645. *
  646. * @return \DateTime
  647. */
  648. public function getIndexedAt()
  649. {
  650. return $this->indexedAt;
  651. }
  652. /**
  653. * Set dumpedAt
  654. *
  655. * @param \DateTime $dumpedAt
  656. */
  657. public function setDumpedAt($dumpedAt)
  658. {
  659. $this->dumpedAt = $dumpedAt;
  660. }
  661. /**
  662. * Get dumpedAt
  663. *
  664. * @return \DateTime
  665. */
  666. public function getDumpedAt()
  667. {
  668. return $this->dumpedAt;
  669. }
  670. /**
  671. * Add maintainers
  672. *
  673. * @param User $maintainer
  674. */
  675. public function addMaintainer(User $maintainer)
  676. {
  677. $this->maintainers[] = $maintainer;
  678. }
  679. /**
  680. * Get maintainers
  681. *
  682. * @return \Doctrine\Common\Collections\Collection
  683. */
  684. public function getMaintainers()
  685. {
  686. return $this->maintainers;
  687. }
  688. /**
  689. * Set type
  690. *
  691. * @param string $type
  692. */
  693. public function setType($type)
  694. {
  695. $this->type = $type;
  696. }
  697. /**
  698. * Get type
  699. *
  700. * @return string
  701. */
  702. public function getType()
  703. {
  704. return $this->type;
  705. }
  706. /**
  707. * Set autoUpdated
  708. *
  709. * @param Boolean $autoUpdated
  710. */
  711. public function setAutoUpdated($autoUpdated)
  712. {
  713. $this->autoUpdated = $autoUpdated;
  714. }
  715. /**
  716. * Get autoUpdated
  717. *
  718. * @return Boolean
  719. */
  720. public function isAutoUpdated()
  721. {
  722. return $this->autoUpdated;
  723. }
  724. /**
  725. * Set updateFailureNotified
  726. *
  727. * @param Boolean $updateFailureNotified
  728. */
  729. public function setUpdateFailureNotified($updateFailureNotified)
  730. {
  731. $this->updateFailureNotified = $updateFailureNotified;
  732. }
  733. /**
  734. * Get updateFailureNotified
  735. *
  736. * @return Boolean
  737. */
  738. public function isUpdateFailureNotified()
  739. {
  740. return $this->updateFailureNotified;
  741. }
  742. /**
  743. * @return boolean
  744. */
  745. public function isAbandoned()
  746. {
  747. return $this->abandoned;
  748. }
  749. /**
  750. * @param boolean $abandoned
  751. */
  752. public function setAbandoned($abandoned)
  753. {
  754. $this->abandoned = $abandoned;
  755. }
  756. /**
  757. * @return string
  758. */
  759. public function getReplacementPackage()
  760. {
  761. return $this->replacementPackage;
  762. }
  763. /**
  764. * @param string $replacementPackage
  765. */
  766. public function setReplacementPackage($replacementPackage)
  767. {
  768. $this->replacementPackage = $replacementPackage;
  769. }
  770. public static function sortVersions($a, $b)
  771. {
  772. $aVersion = $a->getNormalizedVersion();
  773. $bVersion = $b->getNormalizedVersion();
  774. $aVersion = preg_replace('{^dev-.*}', '0.0.0-alpha', $aVersion);
  775. $bVersion = preg_replace('{^dev-.*}', '0.0.0-alpha', $bVersion);
  776. // equal versions are sorted by date
  777. if ($aVersion === $bVersion) {
  778. return $b->getReleasedAt() > $a->getReleasedAt() ? 1 : -1;
  779. }
  780. // the rest is sorted by version
  781. return version_compare($bVersion, $aVersion);
  782. }
  783. }