MediaWiki master
GlobalVarConfig.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Config;
24
31class GlobalVarConfig implements Config {
32
37 private $prefix;
38
43 public static function newInstance() {
44 return new self();
45 }
46
52 public function __construct( $prefix = 'wg' ) {
53 $this->prefix = $prefix;
54 }
55
59 public function get( $name ) {
60 if ( !$this->has( $name ) ) {
61 throw new ConfigException( __METHOD__ . ": undefined option: '$name'" );
62 }
63 return $GLOBALS[$this->prefix . $name];
64 }
65
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 );
76 }
77}
78
80class_alias( GlobalVarConfig::class, 'GlobalVarConfig' );
Exceptions for config failures.
Accesses configuration settings from $GLOBALS.
has( $name)
Check whether a configuration option is set for the given name.bool 1.24
static newInstance()
Default builder function.
Interface for configuration instances.
Definition Config.php:32