| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\Util; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class is an helper utility to parse the version of PHP and convert it |
| 8 |
* to a normalized form. |
| 9 |
* |
| 10 |
* @internal |
| 11 |
*/ |
| 12 |
final class PHPVersion |
| 13 |
{ |
| 14 |
private const VERSION_PARSING_REGEX = '/^(?<base>\\d\\.\\d\\.\\d{1,2})(?<extra>-(beta|rc)-?(\\d+)?(-dev)?)?/i'; |
| 15 |
/** |
| 16 |
* Parses the given string representing a PHP version and returns it in a |
| 17 |
* normalized form. |
| 18 |
* |
| 19 |
* @param string $version The string to parse |
| 20 |
*/ |
| 21 |
public static function parseVersion(string $version = \PHP_VERSION) : string |
| 22 |
{ |
| 23 |
$matches = []; |
| 24 |
if (!\preg_match(self::VERSION_PARSING_REGEX, $version, $matches)) { |
| 25 |
return $version; |
| 26 |
} |
| 27 |
$version = $matches['base']; |
| 28 |
if (isset($matches['extra'])) { |
| 29 |
$version .= $matches['extra']; |
| 30 |
} |
| 31 |
return $version; |
| 32 |
} |
| 33 |
} |
| 34 |
|