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
23 namespace MediaWiki\Config
;
26 * Accesses configuration settings from $GLOBALS
31 class GlobalVarConfig
implements Config
{
34 * Prefix to use for configuration variables
40 * Default builder function
43 public static function newInstance() {
50 * @param string $prefix
52 public function __construct( $prefix = 'wg' ) {
53 $this->prefix
= $prefix;
59 public function get( $name ) {
60 if ( !$this->has( $name ) ) {
61 throw new ConfigException( __METHOD__
. ": undefined option: '$name'" );
63 return $GLOBALS[$this->prefix
. $name];
69 public function has( $name ) {
70 $var = $this->prefix
. $name;
71 // (T317951) Don't call array_key_exists unless we have to, as it's slow
72 // on PHP 8.1+ for $GLOBALS. When the key is set but is explicitly set
73 // to null, we still need to fall back to array_key_exists, but that's
75 return isset( $GLOBALS[$var] ) ||
array_key_exists( $var, $GLOBALS );
79 /** @deprecated class alias since 1.41 */
80 class_alias( GlobalVarConfig
::class, 'GlobalVarConfig' );