parent
757e993871
commit
7577b37cdb
|
@ -1,2 +1 @@
|
|||
GitCommitID: $Format:%H%d$
|
||||
GitCommitDate: $Format:%ci$
|
||||
$Format:%H%d %ci$
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
'gitCommitID' => $this->translate('Git commit ID: %s'),
|
||||
'gitCommitDate' => $this->translate('Git commit date: %s')
|
||||
) as $key => $label) {
|
||||
if (null !== ($value = $version[$key])) {
|
||||
if (array_key_exists($key, $version) && null !== ($value = $version[$key])) {
|
||||
$versionInfo[] = sprintf($label, htmlspecialchars($value));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,91 +15,29 @@ class Version
|
|||
*/
|
||||
public static function get()
|
||||
{
|
||||
$versionInfo = array(
|
||||
'appVersion' => null,
|
||||
'gitCommitID' => null,
|
||||
'gitCommitDate' => null
|
||||
);
|
||||
|
||||
if (false !== ($appVersion = @file(
|
||||
Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION',
|
||||
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
|
||||
if (false === ($appVersion = @file_get_contents(
|
||||
Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION'
|
||||
))) {
|
||||
foreach ($appVersion as $av) {
|
||||
$matches = array();
|
||||
if (false === ($res = preg_match(
|
||||
'/(?<!.)\s*(.+?)\s*:\s*(.+?)\s*(?!.)/ms', $av, $matches
|
||||
))) {
|
||||
throw new IcingaException('Failed at preg_match()');
|
||||
}
|
||||
if ($res === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($matches[1]) {
|
||||
case 'GitCommitID':
|
||||
if ($versionInfo['gitCommitID'] !== null) {
|
||||
break;
|
||||
}
|
||||
|
||||
$matches2 = array();
|
||||
if (false === ($res = preg_match(
|
||||
'/(?<!.)(.+?)(?:\s*\(\s*(.+?)\s*\))?(?!.)/ms',
|
||||
$matches[2],
|
||||
$matches2
|
||||
))) {
|
||||
throw new IcingaException('Failed at preg_match()');
|
||||
}
|
||||
if ($res === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$versionInfo['gitCommitID'] = $matches2[1];
|
||||
if (! isset($matches2[2])) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (preg_split(
|
||||
'/\s*,\s*/', $matches2[2], -1, PREG_SPLIT_NO_EMPTY
|
||||
) as $refName) {
|
||||
$matches3 = array();
|
||||
if (false === ($res = preg_match(
|
||||
'/(?<!.)tag\s*:\s*v(.+?)(?!.)/ms',
|
||||
$refName,
|
||||
$matches3
|
||||
))) {
|
||||
throw new IcingaException('Failed at preg_match()');
|
||||
}
|
||||
if ($res === 1) {
|
||||
$versionInfo['appVersion'] = $matches3[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'GitCommitDate':
|
||||
if ($versionInfo['gitCommitDate'] !== null) {
|
||||
break;
|
||||
}
|
||||
|
||||
$matches2 = array();
|
||||
if (false === ($res = preg_match(
|
||||
'/(?<!.)(\S+)/ms', $matches[2], $matches2
|
||||
))) {
|
||||
throw new IcingaException('Failed at preg_match()');
|
||||
}
|
||||
if ($res === 1) {
|
||||
$versionInfo['gitCommitDate'] = $matches2[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array('gitCommitID', 'gitCommitDate') as $key) {
|
||||
if ($versionInfo[$key] === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$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
|
||||
))) {
|
||||
throw new IcingaException('Failed at preg_match()');
|
||||
}
|
||||
if ($res === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $versionInfo;
|
||||
foreach ($matches as $key => $value) {
|
||||
if (is_int($key) || $value === '') {
|
||||
unset($matches[$key]);
|
||||
}
|
||||
}
|
||||
return $matches;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue