-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1ca9ce
commit 83f89bf
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Commands\Concerns; | ||
|
||
trait InteractsWithVersions | ||
{ | ||
/** | ||
* Warns the user about the latest version of Forge CLI. | ||
* | ||
* @return void | ||
*/ | ||
protected function ensureLatestVersion() | ||
{ | ||
$current = 'v' . config('app.version'); | ||
|
||
if (version_compare($remote = $this->getLatestVersion(), $current) > 0) { | ||
$this->warnStep(['You are using an outdated version %s of Forge CLI. Please update to %s.', $current, $remote]); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the latest version. | ||
* | ||
* @return string | ||
*/ | ||
protected function getLatestVersion() | ||
{ | ||
$resolver = function () { | ||
$package = json_decode(file_get_contents( | ||
'https://packagist.org/p2/laravel/forge-cli.json' | ||
), true); | ||
|
||
return collect($package['packages']['laravel/forge-cli']) | ||
->first()['version']; | ||
}; | ||
|
||
if (is_null($this->config->get('latest_version_verified_at'))) { | ||
$this->config->set('latest_version_verified_at', now()->timestamp); | ||
} | ||
|
||
if (is_null($this->config->get('latest_version'))) { | ||
$this->config->set('latest_version', call_user_func($resolver)); | ||
} | ||
|
||
if ($this->config->get('latest_version_verified_at') < now()->subDays(1)->timestamp) { | ||
$this->config->set('latest_version', call_user_func($resolver)); | ||
$this->config->set('latest_version_verified_at', now()->timestamp); | ||
} | ||
|
||
return $this->config->get('latest_version'); | ||
} | ||
} |