‪TYPO3CMS  ‪main
VersionNumberUtility.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
26 {
33  public static function ‪convertVersionNumberToInteger(string $versionNumber): int
34  {
35  $versionParts = explode('.', $versionNumber);
36  $version = $versionParts[0];
37  for ($i = 1; $i < 3; $i++) {
38  if (!empty($versionParts[$i])) {
39  $version .= str_pad((string)(int)$versionParts[$i], 3, '0', STR_PAD_LEFT);
40  } else {
41  $version .= '000';
42  }
43  }
44  return (int)$version;
45  }
46 
51  public static function ‪getNumericTypo3Version(): string
52  {
53  $t3version = static::getCurrentTypo3Version();
54  $t3version = preg_replace('/-?(dev|alpha|beta|RC).*$/', '', $t3version);
55  $parts = ‪GeneralUtility::intExplode('.', $t3version . '..');
56  $t3version = ‪MathUtility::forceIntegerInRange($parts[0], 0, 999) . '.' .
57  ‪MathUtility::forceIntegerInRange($parts[1], 0, 999) . '.' .
58  ‪MathUtility::forceIntegerInRange($parts[2], 0, 999);
59  return $t3version;
60  }
61 
66  public static function ‪getCurrentTypo3Version(): string
67  {
68  return (string)GeneralUtility::makeInstance(Typo3Version::class);
69  }
70 
79  public static function ‪convertVersionsStringToVersionNumbers(string $versionsString): array
80  {
81  $versions = ‪GeneralUtility::trimExplode('-', $versionsString);
82  foreach ($versions as $i => $version) {
83  $cleanedVersion = ‪GeneralUtility::trimExplode('.', $version);
84  foreach ($cleanedVersion as $j => $cleaned) {
85  $cleanedVersion[$j] = ‪MathUtility::forceIntegerInRange((int)$cleaned, 0, 999);
86  }
87  $cleanedVersionString = implode('.', $cleanedVersion);
88  if (static::convertVersionNumberToInteger($cleanedVersionString) === 0) {
89  $cleanedVersionString = '';
90  }
91  $versions[$i] = $cleanedVersionString;
92  }
93  return $versions;
94  }
95 
103  public static function convertVersionStringToArray(string $version): array
104  {
105  $parts = ‪GeneralUtility::intExplode('.', $version . '..');
106  $parts[0] = ‪MathUtility::forceIntegerInRange($parts[0], 0, 999);
107  $parts[1] = ‪MathUtility::forceIntegerInRange($parts[1], 0, 999);
108  $parts[2] = ‪MathUtility::forceIntegerInRange($parts[2], 0, 999);
109  $result = [];
110  $result['version'] = $parts[0] . '.' . $parts[1] . '.' . $parts[2];
111  $result['version_int'] = (int)($parts[0] * 1000000 + $parts[1] * 1000 + $parts[2]);
112  $result['version_main'] = $parts[0];
113  $result['version_sub'] = $parts[1];
114  $result['version_dev'] = $parts[2];
115  return $result;
116  }
117 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:26
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger(string $versionNumber)
Definition: VersionNumberUtility.php:33
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Core\Utility
Definition: ArrayUtility.php:18
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static getNumericTypo3Version()
Definition: VersionNumberUtility.php:51
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionsStringToVersionNumbers
‪static string[] convertVersionsStringToVersionNumbers(string $versionsString)
Definition: VersionNumberUtility.php:79
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getCurrentTypo3Version
‪static getCurrentTypo3Version()
Definition: VersionNumberUtility.php:66
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static list< int > intExplode(string $delimiter, string $string, bool $removeEmptyValues=false)
Definition: GeneralUtility.php:756
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822