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