Skip to content

Commit

Permalink
Изменена функция для показа версии приложения
Browse files Browse the repository at this point in the history
  • Loading branch information
audetv committed Mar 31, 2023
1 parent 986b251 commit 4ce795c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
3 changes: 1 addition & 2 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"la-haute-societe/yii2-save-relations-behavior": "dev-master",
"sentry/sdk": "dev-master",
"twig/twig": "3.x-dev",
"yiisoft/yii2-redis": "^2.0@dev",
"ext-curl": "*"
"yiisoft/yii2-redis": "^2.0@dev"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",
Expand Down
29 changes: 3 additions & 26 deletions app/src/helpers/VersionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,12 @@
class VersionHelper
{
/**
* Возвращает версию приложения из репозитория github
* Возвращает версию приложения
* @return string
*/
public static function version(): string
{
$cache = \Yii::$app->cache;

return $cache->getOrSet('version', function () {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/vnd.github+json',
'X-GitHub-Api-Version: 2022-11-28',
'User-Agent: fct-search-app'
]);
curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/audetv/fct-search/releases/latest');
$result = curl_exec($ch);
curl_close($ch);

$json = json_decode($result, true);

$tag_name = $json['tag_name'] ?? '';
$html_url = $json['html_url'] ?? '';

if ($tag_name && $html_url) {
return Html::a($json['tag_name'], $json['html_url'], ['target' => '_blank']);
}

return '';
});
$version = 'v0.2.2';
return Html::a($version, 'https://github.com/audetv/fct-search/releases/latest', ['target' => '_blank']);
}
}

0 comments on commit 4ce795c

Please sign in to comment.