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     * Parse the given version string into its parts
14     *
15     * @param string $version
16     * @return array
17     * @throws \Exception
18     */
19    public static function parseVersionString($version)
20    {
21        $return = [
22            'type' => '', // stable, rc
23            'date' => '', // YYYY-MM-DD
24            'hotfix' => '', // a, b, c, ...
25            'version' => '', // sortable, full version string
26            'codename' => '', // codename
27            'raw' => $version, // raw version string as given
28        ];
29
30        if (preg_match('/^(rc)?(\d{4}-\d{2}-\d{2})([a-z]*)/', $version, $matches)) {
31            $return['date'] = $matches[2];
32            if ($matches[1] == 'rc') {
33                $return['type'] = 'rc';
34            } else {
35                $return['type'] = 'stable';
36            }
37            if ($matches[3]) {
38                $return['hotfix'] = $matches[3];
39            }
40        } else {
41            throw new \Exception('failed to parse version string');
42        }
43
44        [, $return['codename']] = sexplode(' ', $version, 2);
45        $return['codename'] = trim($return['codename'], ' "');
46
47        $return['version'] = $return['date'];
48        $return['version'] .= $return['type'] == 'rc' ? 'rc' : $return['hotfix'];
49
50        return $return;
51    }
52}
53