Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Version | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
getBuildVersion | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | /** |
4 | * Version check utility |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * Copyright (C) The National Library of Finland 2015. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package Controller |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org Main Site |
30 | */ |
31 | |
32 | namespace VuFind\Config; |
33 | |
34 | /** |
35 | * Version check utility |
36 | * |
37 | * @category VuFind |
38 | * @package Controller |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Site |
43 | */ |
44 | class Version |
45 | { |
46 | /** |
47 | * Extract version number from the build.xml file of the running instance or |
48 | * another instance pointed to by $dir |
49 | * |
50 | * @param string $dir Optional directory containing build.xml |
51 | * |
52 | * @throws \Exception |
53 | * @return string |
54 | */ |
55 | public static function getBuildVersion($dir = '') |
56 | { |
57 | static $cachedVersions = []; |
58 | |
59 | if ($dir === '') { |
60 | $dir = realpath(APPLICATION_PATH); |
61 | } |
62 | |
63 | if (!isset($cachedVersions[$dir])) { |
64 | $file = $dir . '/build.xml'; |
65 | $xml = file_exists($file) ? simplexml_load_file($file) : false; |
66 | if (!$xml) { |
67 | throw new \Exception('Cannot load ' . $file . '.'); |
68 | } |
69 | $parts = $xml->xpath('/project/property[@name="version"]/@value'); |
70 | $cachedVersions[$dir] = (string)$parts[0]; |
71 | } |
72 | |
73 | return $cachedVersions[$dir]; |
74 | } |
75 | } |