TYPO3 CMS  TYPO3_6-2
VersionNumberUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Utility;
3 
22 
29  static public function convertVersionNumberToInteger($versionNumber) {
30  $versionParts = explode('.', $versionNumber);
31  return (int)(((int)$versionParts[0] . str_pad((int)$versionParts[1], 3, '0', STR_PAD_LEFT)) . str_pad((int)$versionParts[2], 3, '0', STR_PAD_LEFT));
32  }
33 
41  static public function convertIntegerToVersionNumber($versionInteger) {
42  if (!is_int($versionInteger)) {
43  throw new \InvalidArgumentException('TYPO3\\CMS\\Core\\Utility\\VersionNumberUtility::convertIntegerToVersionNumber() supports an integer argument only!', 1334072223);
44  }
45  $versionString = str_pad($versionInteger, 9, '0', STR_PAD_LEFT);
46  $parts = array(
47  substr($versionString, 0, 3),
48  substr($versionString, 3, 3),
49  substr($versionString, 6, 3)
50  );
51  return (int)$parts[0] . '.' . (int)$parts[1] . '.' . (int)$parts[2];
52  }
53 
64  static public function splitVersionRange($version) {
65  $versionRange = array();
66  if (strstr($version, '-')) {
67  $versionRange = explode('-', $version, 2);
68  } else {
69  $versionRange[0] = $version;
70  $versionRange[1] = '';
71  }
72  if (!$versionRange[0]) {
73  $versionRange[0] = '0.0.0';
74  }
75  if (!$versionRange[1]) {
76  $versionRange[1] = '0.0.0';
77  }
78  return $versionRange;
79  }
80 
87  static public function getNumericTypo3Version() {
88  $t3version = static::getCurrentTypo3Version();
89  $t3version = preg_replace('/-?(dev|alpha|beta|RC).*$/', '', $t3version);
90  $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode('.', $t3version . '..');
91  $t3version = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[0], 0, 999) . '.' .
94  return $t3version;
95  }
96 
103  static public function getCurrentTypo3Version() {
104  return TYPO3_version;
105  }
106 
115  static public function convertVersionsStringToVersionNumbers($versionsString) {
116  $versions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('-', $versionsString);
117  $versionsCount = count($versions);
118  for ($i = 0; $i < $versionsCount; $i++) {
119  $cleanedVersion = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $versions[$i]);
120  $cleanedVersionCount = count($cleanedVersion);
121  for ($j = 0; $j < $cleanedVersionCount; $j++) {
122  $cleanedVersion[$j] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cleanedVersion[$j], 0, 999);
123  }
124  $cleanedVersionString = implode('.', $cleanedVersion);
125  if (static::convertVersionNumberToInteger($cleanedVersionString) === 0) {
126  $cleanedVersionString = '';
127  }
128  $versions[$i] = $cleanedVersionString;
129  }
130  return $versions;
131  }
132 
140  static public function convertVersionStringToArray($version) {
141  $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode('.', $version . '..');
142  $parts[0] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[0], 0, 999);
143  $parts[1] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[1], 0, 999);
144  $parts[2] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[2], 0, 999);
145  $result = array();
146  $result['version'] = $parts[0] . '.' . $parts[1] . '.' . $parts[2];
147  $result['version_int'] = (int)($parts[0] * 1000000 + $parts[1] * 1000 + $parts[2]);
148  $result['version_main'] = $parts[0];
149  $result['version_sub'] = $parts[1];
150  $result['version_dev'] = $parts[2];
151  return $result;
152  }
153 
162  static public function raiseVersionNumber($raise, $version) {
163  if (!in_array($raise, array('main', 'sub', 'dev'))) {
164  throw new \TYPO3\CMS\Core\Exception('RaiseVersionNumber expects one of "main", "sub" or "dev".', 1342639555);
165  }
166  $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode('.', $version . '..');
167  $parts[0] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[0], 0, 999);
168  $parts[1] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[1], 0, 999);
169  $parts[2] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($parts[2], 0, 999);
170  switch ((string) $raise) {
171  case 'main':
172  $parts[0]++;
173  $parts[1] = 0;
174  $parts[2] = 0;
175  break;
176  case 'sub':
177  $parts[1]++;
178  $parts[2] = 0;
179  break;
180  case 'dev':
181  $parts[2]++;
182  break;
183  }
184  return $parts[0] . '.' . $parts[1] . '.' . $parts[2];
185  }
186 
187 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
static convertVersionsStringToVersionNumbers($versionsString)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.