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