-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinclude.dependencies.php
101 lines (91 loc) · 2.1 KB
/
include.dependencies.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
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
* CPHP is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
$cphp_dependencies = array();
$cphp_last_dependency = "";
function cphp_dependency_provides($component, $version)
{
global $cphp_dependencies, $cphp_last_dependency;
$cphp_dependencies[$component] = $version;
$cphp_last_dependency = $component;
}
function cphp_dependency_requires($component, $version)
{
global $cphp_dependencies, $cphp_last_dependency;
if(!isset($cphp_dependencies[$component]))
{
die("The {$cphp_last_dependency} component requires the {$component} component to be loaded, but this is not the case.");
}
$current_version = $cphp_dependencies[$component];
if(!cphp_dependency_match($current_version, $version))
{
die("The {$cphp_last_dependency} component requires the {$component} component with version {$version} to be loaded, but an incompatible version ({$current_version}) was found.");
}
}
function cphp_dependency_match($available, $required)
{
if(strpos($required, ",") !== false)
{
$ranges = explode(",", $required);
}
else
{
$ranges[] = $version;
}
foreach($ranges as $range)
{
if(strpos($required, "|") !== false)
{
list($min, $max) = explode("|", $range);
$f_min = (float) $min;
$f_max = (float) $max;
$f_cur = (float) $available;
if(empty($min) && empty($max))
{
return true;
}
elseif(empty($min))
{
if($f_cur < $f_max)
{
return true;
}
else
{
return false;
}
}
elseif(empty($max))
{
if($f_cur > $f_min)
{
return true;
}
else
{
return false;
}
}
else
{
if($f_cur > $f_min && $f_cur < $f_max)
{
return true;
}
else
{
return false;
}
}
}
}
}