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