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
|
|
|
|
|
|
|
class Version
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get the version of this instance of Icinga Web 2
|
|
|
|
*
|
|
|
|
* @return array|bool array on success, false otherwise
|
|
|
|
*/
|
|
|
|
public static function get()
|
|
|
|
{
|
2015-06-03 15:28:36 +02:00
|
|
|
if (false === ($appVersion = @file_get_contents(
|
|
|
|
Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION'
|
2015-06-03 14:40:58 +02:00
|
|
|
))) {
|
2015-06-03 15:28:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-03 14:40:58 +02:00
|
|
|
|
2015-06-03 15:28:36 +02:00
|
|
|
$matches = array();
|
|
|
|
if (false === ($res = preg_match(
|
|
|
|
'/(?<!.)\s*(?P<gitCommitID>\w+)(?:\s*\(.*?(?:(?<=[\(,])\s*tag\s*:\s*v(?P<appVersion>.+?)\s*(?=[\),]).*?)?\))?\s*(?P<gitCommitDate>\S+)/ms',
|
|
|
|
$appVersion,
|
|
|
|
$matches
|
2015-06-05 10:23:17 +02:00
|
|
|
)) || $res === 0) {
|
2015-06-03 15:28:36 +02:00
|
|
|
return false;
|
2015-06-03 14:40:58 +02:00
|
|
|
}
|
|
|
|
|
2015-06-03 15:28:36 +02:00
|
|
|
foreach ($matches as $key => $value) {
|
|
|
|
if (is_int($key) || $value === '') {
|
|
|
|
unset($matches[$key]);
|
2015-06-03 14:40:58 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-03 15:28:36 +02:00
|
|
|
return $matches;
|
2015-06-03 14:40:58 +02:00
|
|
|
}
|
|
|
|
}
|