Info.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace dokuwiki;
  3. /**
  4. * Basic Information about DokuWiki
  5. *
  6. * @todo much of infoutils should be moved here
  7. */
  8. class Info
  9. {
  10. /**
  11. * Parse the given version string into its parts
  12. *
  13. * @param string $version
  14. * @return array
  15. * @throws \Exception
  16. */
  17. static public function parseVersionString($version)
  18. {
  19. $return = [
  20. 'type' => '', // stable, rc
  21. 'date' => '', // YYYY-MM-DD
  22. 'hotfix' => '', // a, b, c, ...
  23. 'version' => '', // sortable, full version string
  24. 'codename' => '', // codename
  25. 'raw' => $version, // raw version string as given
  26. ];
  27. if (preg_match('/^(rc)?(\d{4}-\d{2}-\d{2})([a-z]*)/', $version, $matches)) {
  28. $return['date'] = $matches[2];
  29. if ($matches[1] == 'rc') {
  30. $return['type'] = 'rc';
  31. } else {
  32. $return['type'] = 'stable';
  33. }
  34. if ($matches[3]) {
  35. $return['hotfix'] = $matches[3];
  36. }
  37. } else {
  38. throw new \Exception('failed to parse version string');
  39. }
  40. [, $return['codename']] = sexplode(' ', $version, 2);
  41. $return['codename'] = trim($return['codename'], ' "');
  42. $return['version'] = $return['date'];
  43. $return['version'] .= $return['type'] == 'rc' ? 'rc' : $return['hotfix'];
  44. return $return;
  45. }
  46. }