123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /**
- * @package Grav\Common\GPM
- *
- * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
- * @license MIT License; see LICENSE file for details.
- */
- namespace Grav\Common\GPM;
- use Grav\Common\GPM\Remote\GravCore;
- /**
- * Class Upgrader
- *
- * @package Grav\Common\GPM
- */
- class Upgrader
- {
- /**
- * Remote details about latest Grav version
- *
- * @var GravCore
- */
- private $remote;
- private $min_php;
- /**
- * Creates a new GPM instance with Local and Remote packages available
- *
- * @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
- * @param callable $callback Either a function or callback in array notation
- * @throws \InvalidArgumentException
- */
- public function __construct($refresh = false, $callback = null)
- {
- $this->remote = new Remote\GravCore($refresh, $callback);
- }
- /**
- * Returns the release date of the latest version of Grav
- *
- * @return string
- */
- public function getReleaseDate()
- {
- return $this->remote->getDate();
- }
- /**
- * Returns the version of the installed Grav
- *
- * @return string
- */
- public function getLocalVersion()
- {
- return GRAV_VERSION;
- }
- /**
- * Returns the version of the remotely available Grav
- *
- * @return string
- */
- public function getRemoteVersion()
- {
- return $this->remote->getVersion();
- }
- /**
- * Returns an array of assets available to download remotely
- *
- * @return array
- */
- public function getAssets()
- {
- return $this->remote->getAssets();
- }
- /**
- * Returns the changelog list for each version of Grav
- *
- * @param string $diff the version number to start the diff from
- *
- * @return array return the changelog list for each version
- */
- public function getChangelog($diff = null)
- {
- return $this->remote->getChangelog($diff);
- }
- /**
- * Make sure this meets minimum PHP requirements
- *
- * @return bool
- */
- public function meetsRequirements()
- {
- $current_php_version = phpversion();
- if (version_compare($current_php_version, $this->minPHPVersion(), '<')) {
- return false;
- }
- return true;
- }
- /**
- * Get minimum PHP version from remote
- *
- * @return null
- */
- public function minPHPVersion()
- {
- if (null === $this->min_php) {
- $this->min_php = $this->remote->getMinPHPVersion();
- }
- return $this->min_php;
- }
- /**
- * Checks if the currently installed Grav is upgradable to a newer version
- *
- * @return boolean True if it's upgradable, False otherwise.
- */
- public function isUpgradable()
- {
- return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), '<');
- }
- /**
- * Checks if Grav is currently symbolically linked
- *
- * @return boolean True if Grav is symlinked, False otherwise.
- */
- public function isSymlink()
- {
- return $this->remote->isSymlink();
- }
- }
|