Upgrader.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Grav\Common\GPM;
  3. class Upgrader
  4. {
  5. /**
  6. * Remote details about latest Grav version
  7. * @var Packages
  8. */
  9. private $remote;
  10. /**
  11. * Internal cache
  12. * @var Iterator
  13. */
  14. protected $cache;
  15. /**
  16. * Creates a new GPM instance with Local and Remote packages available
  17. * @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
  18. * @param callable $callback Either a function or callback in array notation
  19. */
  20. public function __construct($refresh = false, $callback = null)
  21. {
  22. $this->remote = new Remote\Grav($refresh, $callback);
  23. }
  24. /**
  25. * Returns the release date of the latest version of Grav
  26. * @return string
  27. */
  28. public function getReleaseDate()
  29. {
  30. return $this->remote->getDate();
  31. }
  32. /**
  33. * Returns the version of the installed Grav
  34. * @return string
  35. */
  36. public function getLocalVersion()
  37. {
  38. return GRAV_VERSION;
  39. }
  40. /**
  41. * Returns the version of the remotely available Grav
  42. * @return string
  43. */
  44. public function getRemoteVersion()
  45. {
  46. return $this->remote->getVersion();
  47. }
  48. /**
  49. * Returns an array of assets available to download remotely
  50. * @return array
  51. */
  52. public function getAssets()
  53. {
  54. return $this->remote->getAssets();
  55. }
  56. /**
  57. * Returns the changelog list for each version of Grav
  58. * @param string $diff the version number to start the diff from
  59. *
  60. * @return array return the changelog list for each version
  61. */
  62. public function getChangelog($diff = null)
  63. {
  64. return $this->remote->getChangelog($diff);
  65. }
  66. /**
  67. * Checks if the currently installed Grav is upgradable to a newer version
  68. * @return boolean True if it's upgradable, False otherwise.
  69. */
  70. public function isUpgradable()
  71. {
  72. return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), "<");
  73. }
  74. /**
  75. * Checks if Grav is currently symbolically linked
  76. * @return boolean True if Grav is symlinked, False otherwise.
  77. */
  78. public function isSymlink()
  79. {
  80. return $this->remote->isSymlink();
  81. }
  82. }