icingaweb2/library/Icinga/Application/Version.php

59 lines
1.8 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
{
/**
* Get the version of this instance of Icinga Web 2
*
2015-08-27 13:06:49 +02:00
* @return array|false array on success, false otherwise
*/
public static function get()
{
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 $matches;
}
}
}
2015-09-23 17:48:30 +02:00
if (false === ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('VERSION')))) {
2015-06-03 15:28:36 +02:00
return false;
}
2015-06-03 15:28:36 +02:00
$matches = array();
2015-09-23 17:48:30 +02:00
if (! @preg_match('/^(?P<gitCommitID>\S+)(?: \((.+?)\))? (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
2015-06-03 15:28:36 +02:00
return false;
}
2015-09-23 17:48:30 +02:00
if (array_key_exists(1, $matches)) {
$tagMatches = array();
foreach (explode(', ', $matches[1]) as $gitRef) {
if (@preg_match('/^tag: v(.+)/', $gitRef, $tagMatches)) {
$matches['appVersion'] = $tagMatches[1];
break;
}
}
2015-09-23 17:48:30 +02:00
unset($matches[1]);
}
2015-09-23 17:48:30 +02:00
2015-06-03 15:28:36 +02:00
return $matches;
}
}