5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Accesses configuration settings from $GLOBALS
28 class GlobalVarConfig
implements Config
{
31 * Prefix to use for configuration variables
37 * Default builder function
38 * @return GlobalVarConfig
40 public static function newInstance() {
41 return new GlobalVarConfig();
44 public function __construct( $prefix = 'wg' ) {
45 $this->prefix
= $prefix;
51 public function get( $name ) {
52 if ( !$this->has( $name ) ) {
53 throw new ConfigException( __METHOD__
. ": undefined option: '$name'" );
55 return $this->getWithPrefix( $this->prefix
, $name );
61 public function has( $name ) {
62 return $this->hasWithPrefix( $this->prefix
, $name );
66 * Get a variable with a given prefix, if not the defaults.
68 * @param string $prefix Prefix to use on the variable, if one.
69 * @param string $name Variable name without prefix
72 protected function getWithPrefix( $prefix, $name ) {
73 return $GLOBALS[$prefix . $name];
77 * Check if a variable with a given prefix is set
79 * @param string $prefix Prefix to use on the variable
80 * @param string $name Variable name without prefix
83 protected function hasWithPrefix( $prefix, $name ) {
84 $var = $prefix . $name;
85 return array_key_exists( $var, $GLOBALS );