Merge "Make the PHP code snippet in SkinFallbackTemplate explicitly ltr"
[mediawiki.git] / includes / config / GlobalVarConfig.php
blob0841a00419767dd1fe309b2a0822545411b49b19
1 <?php
2 /**
3 * Copyright 2014
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
20 * @file
23 /**
24 * Accesses configuration settings from $GLOBALS
26 * @since 1.23
28 class GlobalVarConfig implements Config {
30 /**
31 * Prefix to use for configuration variables
32 * @var string
34 private $prefix;
36 /**
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;
48 /**
49 * @see Config::get
51 public function get( $name ) {
52 return $this->getWithPrefix( $this->prefix, $name );
55 /**
56 * @see Config::set
58 public function set( $name, $value ) {
59 $this->setWithPrefix( $this->prefix, $name, $value );
62 /**
63 * Get a variable with a given prefix, if not the defaults.
65 * @param string $prefix Prefix to use on the variable, if one.
66 * @param string $name Variable name without prefix
67 * @throws ConfigException
68 * @return mixed
70 protected function getWithPrefix( $prefix, $name ) {
71 $var = $prefix . $name;
72 if ( !array_key_exists( $var, $GLOBALS ) ) {
73 throw new ConfigException( __METHOD__ . ": undefined variable: '$var'" );
75 return $GLOBALS[$var];
78 /**
79 * Get a variable with a given prefix, if not the defaults.
81 * @param string $prefix Prefix to use on the variable
82 * @param string $name Variable name without prefix
83 * @param mixed $value Value to set
85 protected function setWithPrefix( $prefix, $name, $value ) {
86 $GLOBALS[$prefix . $name] = $value;