-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathversions.php
88 lines (79 loc) · 2.28 KB
/
versions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\titania;
class versions
{
/**
* Compare two versions in reverse.
*
* @param string $version1
* @param string $version2
* @return mixed
*/
public static function reverse_version_compare($version1, $version2)
{
return version_compare($version2, $version1);
}
/**
* Order an array of phpBB versions from the database (phpbb_version_branch, phpbb_version_revision)
*
* @param cache\service $cache
* @param array $version_array Array of versions
* @param bool $all_versions Whether the revision in question supports all phpBB versions
* @return array
*/
public static function order_phpbb_version_list_from_db(cache\service $cache, array $version_array, $all_versions = false)
{
if ($all_versions)
{
$all_versions = self::to_string($version_array[0], 'x');
return array($all_versions);
}
$versions = $cache->get_phpbb_versions();
$ordered_phpbb_versions = array();
foreach ($version_array as $row)
{
$ordered_phpbb_versions[$versions[$row['phpbb_version_branch'] . $row['phpbb_version_revision']]] = true;
}
uksort($ordered_phpbb_versions, array('self', 'reverse_version_compare'));
return array_keys($ordered_phpbb_versions);
}
/**
* Generate string representation of a version.
*
* @param array $version Version array in form of array(
* 'phpbb_version_branch' => int,
* 'phpbb_version_revision' => string,
* )
* @param null $revision Optional revision to use instead of that provided in $version
* @return string
*/
public static function to_string(array $version, $revision = null)
{
$string = $version['phpbb_version_branch'][0] . '.' . $version['phpbb_version_branch'][1];
$string .= ($revision !== null) ? ".$revision" : ".{$version['phpbb_version_revision']}";
return $string;
}
/**
* Get branch from version string.
*
* Given 3.1.0, returns 31
*
* @param string $version
* @return int
*/
public static function get_branch_from_string($version)
{
return (int) ($version[0] . $version[2]);
}
}