2015-06-03 14:40:58 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
2015-06-05 10:18:24 +02:00
|
|
|
namespace Icinga\Application;
|
2015-06-03 14:40:58 +02:00
|
|
|
|
2015-08-27 13:06:31 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the version of Icinga Web 2
|
|
|
|
*/
|
2015-06-03 14:40:58 +02:00
|
|
|
class Version
|
|
|
|
{
|
2015-12-22 14:50:13 +01:00
|
|
|
const VERSION = '2.1.1';
|
2015-06-05 12:38:55 +02:00
|
|
|
|
2015-06-03 14:40:58 +02:00
|
|
|
/**
|
|
|
|
* Get the version of this instance of Icinga Web 2
|
|
|
|
*
|
2015-06-05 12:38:55 +02:00
|
|
|
* @return array
|
2015-06-03 14:40:58 +02:00
|
|
|
*/
|
|
|
|
public static function get()
|
|
|
|
{
|
2015-06-05 12:38:55 +02:00
|
|
|
$version = array('appVersion' => self::VERSION);
|
2015-09-30 18:37:48 +02:00
|
|
|
if (false !== ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('VERSION')))) {
|
2015-06-05 12:38:55 +02:00
|
|
|
$matches = array();
|
|
|
|
if (@preg_match('/^(?P<gitCommitID>\w+) (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
|
2015-06-05 12:38:55 +02:00
|
|
|
return array_merge($version, $matches);
|
2015-06-05 12:38:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 15:53:10 +02:00
|
|
|
$gitDir = Icinga::app()->getBaseDir('.git');
|
|
|
|
$gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . 'HEAD');
|
|
|
|
if (false !== $gitHead) {
|
2015-06-05 12:38:55 +02:00
|
|
|
$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)) {
|
2015-06-05 12:38:55 +02:00
|
|
|
return array_merge($version, $matches);
|
2015-09-23 15:53:10 +02:00
|
|
|
}
|
2015-06-05 12:38:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:38:55 +02:00
|
|
|
return $version;
|
2015-06-03 14:40:58 +02:00
|
|
|
}
|
|
|
|
}
|