diff --git a/composer.json b/composer.json index c4e8f4c..68602b2 100755 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "minimum-stability": "stable", "require": { "desarrolla2/cache": "2.1.*", - "monolog/monolog": "1.22.*", + "monolog/monolog": "1.23.*", "php": ">= 5.6.4", - "vierbergenlars/php-semver": "3.0.*" + "composer/semver": "1.4.*" }, "require-dev": { - "phpunit/phpunit": "5.7.*" + "phpunit/phpunit": "6.5.*" }, "autoload": { "psr-4": { diff --git a/src/AutoUpdate.php b/src/AutoUpdate.php index cb6ea6a..7bcde49 100755 --- a/src/AutoUpdate.php +++ b/src/AutoUpdate.php @@ -1,14 +1,13 @@ setTempDir(($tempDir !== null) ? $tempDir : __DIR__ . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR); $this->setInstallDir(($installDir !== null) ? $installDir : __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); - $this->_latestVersion = new version('0.0.0'); - $this->_currentVersion = new version('0.0.0'); + $this->_latestVersion = '0.0.0'; + $this->_currentVersion = '0.0.0'; // Init cache $this->_cache = new Cache(new NotCache()); @@ -306,14 +305,7 @@ public function setCache($adapter, $ttl = 3600) */ public function setCurrentVersion($currentVersion) { - $version = new version($currentVersion); - if ($version->valid() === null) { - $this->_log->addError(sprintf('Invalid current version "%s"', $currentVersion)); - - return false; - } - - $this->_currentVersion = $version; + $this->_currentVersion = $currentVersion; return $this; } @@ -362,7 +354,7 @@ public function addLogHandler(\Monolog\Handler\HandlerInterface $handler) /** * Get the name of the latest version. * - * @return vierbergenlars\SemVer\version + * @return string */ public function getLatestVersion() { @@ -376,9 +368,13 @@ public function getLatestVersion() */ public function getVersionsToUpdate() { - return array_map(function ($update) { - return $update['version']; - }, $this->_updates); + if (count($this->_updates) > 0) { + return array_map(function ($update) { + return $update['version']; + }, $this->_updates); + } + + return []; } /** @@ -432,7 +428,7 @@ public function checkUpdate() $this->_log->addNotice('Checking for a new update...'); // Reset previous updates - $this->_latestVersion = new version('0.0.0'); + $this->_latestVersion = '0.0.0'; $this->_updates = []; $versions = $this->_cache->get('update-versions'); @@ -497,15 +493,9 @@ public function checkUpdate() } // Check for latest version - foreach ($versions as $versionRaw => $updateUrl) { - $version = new version($versionRaw); - if ($version->valid() === null) { - $this->_log->addInfo(sprintf('Could not parse version "%s" from update server "%s"', $versionRaw, $updateFile)); - continue; - } - - if (version::gt($version, $this->_currentVersion)) { - if (version::gt($version, $this->_latestVersion)) + foreach ($versions as $version => $updateUrl) { + if (Comparator::greaterThan($version, $this->_currentVersion)) { + if (Comparator::greaterThan($version, $this->_latestVersion)) $this->_latestVersion = $version; $this->_updates[] = [ @@ -517,7 +507,11 @@ public function checkUpdate() // Sort versions to install usort($this->_updates, function ($a, $b) { - return version::compare($a['version'], $b['version']); + if (Comparator::equalTo($a['version'], $b['version'])) { + return 0; + } + + return Comparator::lessThan($a['version'], $b['version']) ? -1 : 1; }); if ($this->newVersionAvailable()) { @@ -538,7 +532,7 @@ public function checkUpdate() */ public function newVersionAvailable() { - return version::gt($this->_latestVersion, $this->_currentVersion); + return Comparator::greaterThan($this->_latestVersion, $this->_currentVersion); } /**