icingaweb2/library/Icinga/Application/Version.php

41 lines
1.0 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-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;
}
}