<?php
class Foo
{
const VERSION_INFO = '12abc34 (HEAD -> master, tag: 2.0.1)';
static function getVersion(): string
{
if (self::VERSION_INFO[0] === '$') {
// fallback to other methods
return '';
}
if (preg_match('/^([0-9a-f]+).*?tag: ([\d\.]+)/', self::VERSION_INFO, $matched)) {
return "{$matched[2]}-{$matched[1]}";
}
// fallback to other methods
}
}
var_dump(Foo::getVersion());
- Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
- string(13) "2.0.1-12abc34"
preferences:
150.56 ms | 403 KiB | 168 Q