forked from bogdan2412/infoarena
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameter.php
More file actions
49 lines (44 loc) Β· 1.38 KB
/
parameter.php
File metadata and controls
49 lines (44 loc) Β· 1.38 KB
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
<?php
require_once(Config::ROOT . "common/db/db.php");
// FIXME: obliterate?
//
// Parses parameter value as stored in database and returns native PHP value
// $parameter_id parameter type (id)
// $value raw value string stored in database
function parameter_decode($parameter_id, $value) {
$booleans = array('rating_update');
$ints = array('memlimit', 'rating_timestamp');
$floats = array('timelimit');
$strings = array();
if (in_array($parameter_id, $booleans)) {
if ("1" == $value) {
return true;
}
elseif ("0" == $value || "" == $value) {
return false;
}
log_error("Invalid boolean value: ".$value);
}
elseif (in_array($parameter_id, $ints)) {
if (is_whole_number($value)) {
return (int)$value;
}
log_error("Invalid integer value: ".$value);
}
elseif (in_array($parameter_id, $floats)) {
if (is_numeric($value)) {
return (float)$value;
}
log_error("Invalid float value: ".$value);
}
elseif (in_array($parameter_id, $strings)) {
// make sure $value is of type string
if (is_string($value)) {
return $value;
}
log_error("Invalid string value: ".$value);
}
log_error("Unknown parameter id: \"{$parameter_id}\". "
."Value is: \"{$value}\".");
}
?>