Upgrader.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @package Grav\Common\GPM
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\GPM;
  9. use Grav\Common\GPM\Remote\GravCore;
  10. /**
  11. * Class Upgrader
  12. *
  13. * @package Grav\Common\GPM
  14. */
  15. class Upgrader
  16. {
  17. /**
  18. * Remote details about latest Grav version
  19. *
  20. * @var GravCore
  21. */
  22. private $remote;
  23. private $min_php;
  24. /**
  25. * Creates a new GPM instance with Local and Remote packages available
  26. *
  27. * @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
  28. * @param callable $callback Either a function or callback in array notation
  29. * @throws \InvalidArgumentException
  30. */
  31. public function __construct($refresh = false, $callback = null)
  32. {
  33. $this->remote = new Remote\GravCore($refresh, $callback);
  34. }
  35. /**
  36. * Returns the release date of the latest version of Grav
  37. *
  38. * @return string
  39. */
  40. public function getReleaseDate()
  41. {
  42. return $this->remote->getDate();
  43. }
  44. /**
  45. * Returns the version of the installed Grav
  46. *
  47. * @return string
  48. */
  49. public function getLocalVersion()
  50. {
  51. return GRAV_VERSION;
  52. }
  53. /**
  54. * Returns the version of the remotely available Grav
  55. *
  56. * @return string
  57. */
  58. public function getRemoteVersion()
  59. {
  60. return $this->remote->getVersion();
  61. }
  62. /**
  63. * Returns an array of assets available to download remotely
  64. *
  65. * @return array
  66. */
  67. public function getAssets()
  68. {
  69. return $this->remote->getAssets();
  70. }
  71. /**
  72. * Returns the changelog list for each version of Grav
  73. *
  74. * @param string $diff the version number to start the diff from
  75. *
  76. * @return array return the changelog list for each version
  77. */
  78. public function getChangelog($diff = null)
  79. {
  80. return $this->remote->getChangelog($diff);
  81. }
  82. /**
  83. * Make sure this meets minimum PHP requirements
  84. *
  85. * @return bool
  86. */
  87. public function meetsRequirements()
  88. {
  89. $current_php_version = phpversion();
  90. if (version_compare($current_php_version, $this->minPHPVersion(), '<')) {
  91. return false;
  92. }
  93. return true;
  94. }
  95. /**
  96. * Get minimum PHP version from remote
  97. *
  98. * @return null
  99. */
  100. public function minPHPVersion()
  101. {
  102. if (null === $this->min_php) {
  103. $this->min_php = $this->remote->getMinPHPVersion();
  104. }
  105. return $this->min_php;
  106. }
  107. /**
  108. * Checks if the currently installed Grav is upgradable to a newer version
  109. *
  110. * @return boolean True if it's upgradable, False otherwise.
  111. */
  112. public function isUpgradable()
  113. {
  114. return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), '<');
  115. }
  116. /**
  117. * Checks if Grav is currently symbolically linked
  118. *
  119. * @return boolean True if Grav is symlinked, False otherwise.
  120. */
  121. public function isSymlink()
  122. {
  123. return $this->remote->isSymlink();
  124. }
  125. }