Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / config / GlobalVarConfig.php
blob43c23d0635e9ba832dc2841fd27c048c9c2fa52c
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 namespace MediaWiki\Config;
25 /**
26 * Accesses configuration settings from $GLOBALS
28 * @newable
29 * @since 1.23
31 class GlobalVarConfig implements Config {
33 /**
34 * Prefix to use for configuration variables
35 * @var string
37 private $prefix;
39 /**
40 * Default builder function
41 * @return self
43 public static function newInstance() {
44 return new self();
47 /**
48 * @stable to call
50 * @param string $prefix
52 public function __construct( $prefix = 'wg' ) {
53 $this->prefix = $prefix;
56 /**
57 * @inheritDoc
59 public function get( $name ) {
60 if ( !$this->has( $name ) ) {
61 throw new ConfigException( __METHOD__ . ": undefined option: '$name'" );
63 return $GLOBALS[$this->prefix . $name];
66 /**
67 * @inheritDoc
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
74 // rarer.
75 return isset( $GLOBALS[$var] ) || array_key_exists( $var, $GLOBALS );
79 /** @deprecated class alias since 1.41 */
80 class_alias( GlobalVarConfig::class, 'GlobalVarConfig' );