icingaweb2/library/Icinga/Application/Version.php

49 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2013-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
{
2015-12-22 14:50:13 +01:00
const VERSION = '2.1.1';
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);
}
}
2015-09-23 15:53:10 +02:00
$gitDir = Icinga::app()->getBaseDir('.git');
$gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . 'HEAD');
if (false !== $gitHead) {
$matches = array();
2015-09-23 15:53:10 +02:00
if (@preg_match('/(?<!.)ref:\s+(.+?)$/ms', $gitHead, $matches)) {
$gitCommitID = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . $matches[1]);
} else {
$gitCommitID = $gitHead;
}
if (false !== $gitCommitID) {
$matches = array();
if (@preg_match('/(?<!.)(?P<gitCommitID>[0-9a-f]+)$/ms', $gitCommitID, $matches)) {
return array_merge($version, $matches);
2015-09-23 15:53:10 +02:00
}
}
}
return $version;
}
}