‪TYPO3CMS  10.4
VersionNumberUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
32  public static function ‪convertVersionNumberToInteger($versionNumber)
33  {
34  $versionParts = explode('.', $versionNumber);
35  $version = $versionParts[0];
36  for ($i = 1; $i < 3; $i++) {
37  if (!empty($versionParts[$i])) {
38  $version .= str_pad((string)(int)$versionParts[$i], 3, '0', STR_PAD_LEFT);
39  } else {
40  $version .= '000';
41  }
42  }
43  return (int)$version;
44  }
45 
54  public static function ‪convertIntegerToVersionNumber($versionInteger)
55  {
56  trigger_error('Method ' . __METHOD__ . ' will be removed in TYPO3 11.0', E_USER_DEPRECATED);
57 
58  if (!is_int($versionInteger)) {
59  throw new \InvalidArgumentException(\‪TYPO3\CMS\Core\Utility\VersionNumberUtility::class . '::convertIntegerToVersionNumber() supports an integer argument only!', 1334072223);
60  }
61  $versionString = str_pad($versionInteger, 9, '0', STR_PAD_LEFT);
62  $parts = [
63  substr($versionString, 0, 3),
64  substr($versionString, 3, 3),
65  substr($versionString, 6, 3)
66  ];
67  return (int)$parts[0] . '.' . (int)$parts[1] . '.' . (int)$parts[2];
68  }
69 
81  public static function ‪splitVersionRange($version)
82  {
83  trigger_error('Method ' . __METHOD__ . ' will be removed in TYPO3 11.0', E_USER_DEPRECATED);
84 
85  $versionRange = [];
86  if (strpos($version, '-') !== false) {
87  $versionRange = explode('-', $version, 2);
88  } else {
89  $versionRange[0] = $version;
90  $versionRange[1] = '';
91  }
92  if (!$versionRange[0]) {
93  $versionRange[0] = '0.0.0';
94  }
95  if (!$versionRange[1]) {
96  $versionRange[1] = '0.0.0';
97  }
98  return $versionRange;
99  }
100 
107  public static function ‪getNumericTypo3Version()
108  {
109  $t3version = static::getCurrentTypo3Version();
110  $t3version = preg_replace('/-?(dev|alpha|beta|RC).*$/', '', $t3version);
111  $parts = ‪GeneralUtility::intExplode('.', $t3version . '..');
112  $t3version = ‪MathUtility::forceIntegerInRange($parts[0], 0, 999) . '.' .
113  ‪MathUtility::forceIntegerInRange($parts[1], 0, 999) . '.' .
114  ‪MathUtility::forceIntegerInRange($parts[2], 0, 999);
115  return $t3version;
116  }
117 
124  public static function ‪getCurrentTypo3Version()
125  {
126  return (string)GeneralUtility::makeInstance(Typo3Version::class);
127  }
128 
137  public static function ‪convertVersionsStringToVersionNumbers($versionsString)
138  {
139  $versions = ‪GeneralUtility::trimExplode('-', $versionsString);
140  $versionsCount = count($versions);
141  for ($i = 0; $i < $versionsCount; $i++) {
142  $cleanedVersion = ‪GeneralUtility::trimExplode('.', $versions[$i]);
143  $cleanedVersionCount = count($cleanedVersion);
144  for ($j = 0; $j < $cleanedVersionCount; $j++) {
145  $cleanedVersion[$j] = ‪MathUtility::forceIntegerInRange((int)$cleanedVersion[$j], 0, 999);
146  }
147  $cleanedVersionString = implode('.', $cleanedVersion);
148  if (static::convertVersionNumberToInteger($cleanedVersionString) === 0) {
149  $cleanedVersionString = '';
150  }
151  $versions[$i] = $cleanedVersionString;
152  }
153  return $versions;
154  }
155 
163  public static function ‪convertVersionStringToArray($version)
164  {
165  $parts = ‪GeneralUtility::intExplode('.', $version . '..');
166  $parts[0] = ‪MathUtility::forceIntegerInRange($parts[0], 0, 999);
167  $parts[1] = ‪MathUtility::forceIntegerInRange($parts[1], 0, 999);
168  $parts[2] = ‪MathUtility::forceIntegerInRange($parts[2], 0, 999);
169  $result = [];
170  $result['version'] = $parts[0] . '.' . $parts[1] . '.' . $parts[2];
171  $result['version_int'] = (int)($parts[0] * 1000000 + $parts[1] * 1000 + $parts[2]);
172  $result['version_main'] = $parts[0];
173  $result['version_sub'] = $parts[1];
174  $result['version_dev'] = $parts[2];
175  return $result;
176  }
177 
187  public static function ‪raiseVersionNumber($raise, $version)
188  {
189  trigger_error('Method ' . __METHOD__ . ' will be removed in TYPO3 11.0', E_USER_DEPRECATED);
190 
191  if (!in_array($raise, ['main', 'sub', 'dev'])) {
192  throw new ‪Exception('RaiseVersionNumber expects one of "main", "sub" or "dev".', 1342639555);
193  }
194  $parts = ‪GeneralUtility::intExplode('.', $version . '..');
195  $parts[0] = ‪MathUtility::forceIntegerInRange($parts[0], 0, 999);
196  $parts[1] = ‪MathUtility::forceIntegerInRange($parts[1], 0, 999);
197  $parts[2] = ‪MathUtility::forceIntegerInRange($parts[2], 0, 999);
198  switch ((string)$raise) {
199  case 'main':
200  $parts[0]++;
201  $parts[1] = 0;
202  $parts[2] = 0;
203  break;
204  case 'sub':
205  $parts[1]++;
206  $parts[2] = 0;
207  break;
208  case 'dev':
209  $parts[2]++;
210  break;
211  }
212  return $parts[0] . '.' . $parts[1] . '.' . $parts[2];
213  }
214 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static string getNumericTypo3Version()
Definition: VersionNumberUtility.php:107
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertIntegerToVersionNumber
‪static string convertIntegerToVersionNumber($versionInteger)
Definition: VersionNumberUtility.php:54
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionStringToArray
‪static array convertVersionStringToArray($version)
Definition: VersionNumberUtility.php:163
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:22
‪TYPO3
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Utility
Definition: ArrayUtility.php:16
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:32
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\raiseVersionNumber
‪static string raiseVersionNumber($raise, $version)
Definition: VersionNumberUtility.php:187
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getCurrentTypo3Version
‪static string getCurrentTypo3Version()
Definition: VersionNumberUtility.php:124
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\splitVersionRange
‪static array splitVersionRange($version)
Definition: VersionNumberUtility.php:81
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionsStringToVersionNumbers
‪static array convertVersionsStringToVersionNumbers($versionsString)
Definition: VersionNumberUtility.php:137