icingaweb2/library/Icinga/Application/Version.php

63 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Application;
2015-08-27 13:06:31 +02:00
/**
* Retrieve the version of Icinga Web 2
*/
class Version
{
2018-04-25 13:02:47 +02:00
const VERSION = '2.5.2';
2015-06-05 12:38:55 +02:00
/**
* Get the version of this instance of Icinga Web 2
*
* @return array
*/
public static function get()
{
$version = array('appVersion' => self::VERSION);
if (false !== ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('VERSION')))) {
$matches = array();
if (@preg_match('/^(?P<gitCommitID>\w+) (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
return array_merge($version, $matches);
}
}
$gitCommitId = static::getGitHead(Icinga::app()->getBaseDir());
if ($gitCommitId !== false) {
$version['gitCommitID'] = $gitCommitId;
}
return $version;
}
/**
* Get the current commit of the Git repository in the given path
*
* @param string $repo Path to the Git repository
* @param bool $bare Whether the Git repository is bare
*
* @return string|bool False if not available
*/
public static function getGitHead($repo, $bare = false)
{
if (! $bare) {
$repo .= '/.git';
}
$head = @file_get_contents($repo . '/HEAD');
2015-09-23 15:53:10 +02:00
if ($head !== false) {
if (preg_match('/^ref: (.+)/', $head, $matches)) {
return @file_get_contents($repo . '/' . $matches[1]);
}
return $head;
}
return false;
}
}