/
config_api.php
67 lines (58 loc) · 2.23 KB
/
config_api.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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: config_api.php,v 1.3 2002-08-27 10:08:08 jfitzell Exp $
# --------------------------------------------------------
###########################################################################
# Configuration API
###########################################################################
# ------------------
# Retrieves the value of a config option
# This function will return one of (in order of preference):
# 1. The user-defined value (if set)
# 2. The default value (if known)
# 3. The value passed as the second parameter of the function
function config_get( $p_option, $p_default=null ) {
# ------ global variable implementation ------
# this function implements getting configuration
# from our current global variable scheme. This
# interface should remain constant but we could
# call out to other functions or replace this code
# to use a DB or some other method
if ( isset( $GLOBALS['g_'.$p_option] ) ) {
return $GLOBALS['g_'.$p_option];
} else {
# unless we were allowing for the option not to exist by passing
# a default, trigger a NOTICE
if ( null == $p_default ) {
error_parameters($p_option);
trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, NOTICE );
}
return $p_default;
}
}
# ------------------
# Returns true if the specified config option exists (ie. a
# value or default can be found), false otherwise
function config_is_set( $p_option ) {
if ( isset( $GLOBALS['g_'.$p_option] ) ) {
return true;
} else {
return false;
}
}
# ------------------
# Sets the value of the given config option to the given value
# If the config option does not exist, an ERROR is triggered
function config_set( $p_option, $p_value ) {
if ( ! isset( $GLOBALS['g_'.$p_option] ) ) {
trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR );
}
$GLOBALS['g_'.$p_option] = $p_value;
return true;
}
?>