Skip to content

Commit

Permalink
Make regex less complicated
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Sep 23, 2015
1 parent d6cf631 commit 7c3b46f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions library/Icinga/Application/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ public static function get()
}
}

if (false === ($appVersion = @file_get_contents(
Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION'
))) {
if (false === ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('VERSION')))) {
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
)) || $res === 0) {
if (! @preg_match('/^(?P<gitCommitID>\S+)(?: \((.+?)\))? (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
return false;
}

foreach ($matches as $key => $value) {
if (is_int($key) || $value === '') {
unset($matches[$key]);
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;
}
}
unset($matches[1]);
}

return $matches;
}
}

0 comments on commit 7c3b46f

Please sign in to comment.