25use Wikimedia\Assert\Assert;
26use Wikimedia\Services\SalvageableService;
35 private $configFactory;
38 private $configItems = [
47 $this->configFactory = $configFactory;
57 public function has( $name, $alsoPrivate =
false ) {
58 return isset( $this->configItems[
'public'][$name] ) ||
59 ( $alsoPrivate && isset( $this->configItems[
'private'][$name] ) );
70 public function get( $name ) {
71 if ( !$this->
has( $name,
true ) ) {
72 throw new \ConfigException(
'The configuration option ' . $name .
' does not exist.' );
75 return $this->configItems[
'public'][$name] ?? $this->configItems[
'private'][$name];
89 return array_merge( $this->configItems[
'private'], $this->configItems[
'public'] );
98 return $this->configItems[
'public'];
110 $config = $this->
get( $name );
111 if ( !isset( $config[
'configregistry'] ) ) {
112 return $config[
'value'];
115 return $this->configFactory->makeConfig( $config[
'configregistry'] )->get( $name );
127 $config = $this->
get( $name );
128 if ( isset( $config[
'descriptionmsg'] ) ) {
129 return wfMessage( $config[
'descriptionmsg'] )->escaped();
131 if ( isset( $config[
'description'] ) ) {
132 return htmlspecialchars( $config[
'description'] );
152 public function add( $name, array $config ) {
153 if ( $this->
has( $name ) ) {
154 throw new \ConfigException(
'A configuration with the name ' . $name .
155 'does already exist. It is provided by: ' .
156 $this->
get( $name )[
'providedby'] );
158 if ( isset( $config[
'public'] ) && $config[
'public'] ) {
159 $this->configItems[
'public'][$name] = $config;
161 $this->configItems[
'private'][$name] = $config;
172 public function isEmpty( $includePrivate =
false ) {
173 if ( $includePrivate ) {
174 return empty( $this->configItems[
'private'] ) &&
175 empty( $this->configItems[
'public'] );
177 return empty( $this->configItems[
'public'] );
189 public function salvage( SalvageableService $other ) {
190 Assert::parameterType( self::class, $other,
'$other' );
192 '@phan-var self $other';
194 foreach ( $other->configItems[
'public'] as $name => $otherConfig ) {
195 if ( isset( $this->configItems[
'public'][$name] ) ) {
199 $this->
add( $name, $otherConfig );
201 foreach ( $other->configItems[
'private'] as $name => $otherConfig ) {
202 if ( isset( $this->configItems[
'private'][$name] ) ) {
206 $this->
add( $name, $otherConfig );
210 $other->configItems = [];
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Factory class to create Config objects.