icingaweb2/library/Icinga/Application/Version.php

38 lines
1016 B
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Application;
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 15:28:36 +02:00
return false;
}
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 15:28:36 +02:00
foreach ($matches as $key => $value) {
if (is_int($key) || $value === '') {
unset($matches[$key]);
}
}
2015-06-03 15:28:36 +02:00
return $matches;
}
}