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