MediaWiki  1.33.0
ConfigRepository.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Config;
24 
25 use Wikimedia\Assert\Assert;
27 
35  private $configFactory;
36 
38  private $configItems = [
39  'private' => [],
40  'public' => [],
41  ];
42 
47  $this->configFactory = $configFactory;
48  }
49 
57  public function has( $name, $alsoPrivate = false ) {
58  return isset( $this->configItems['public'][$name] ) ||
59  ( $alsoPrivate && isset( $this->configItems['private'][$name] ) );
60  }
61 
70  public function get( $name ) {
71  if ( !$this->has( $name, true ) ) {
72  throw new \ConfigException( 'The configuration option ' . $name . ' does not exist.' );
73  }
74 
75  return $this->configItems['public'][$name] ?? $this->configItems['private'][$name];
76  }
77 
88  public function getAll() {
89  return array_merge( $this->configItems['private'], $this->configItems['public'] );
90  }
91 
97  public function getPublic() {
98  return $this->configItems['public'];
99  }
100 
109  public function getValueOf( $name ) {
110  $config = $this->get( $name );
111  if ( !isset( $config['configregistry'] ) ) {
112  return $config['value'];
113  }
114 
115  return $this->configFactory->makeConfig( $config['configregistry'] )->get( $name );
116  }
117 
126  public function getDescriptionOf( $name ) {
127  $config = $this->get( $name );
128  if ( isset( $config['descriptionmsg'] ) ) {
129  return wfMessage( $config['descriptionmsg'] )->escaped();
130  }
131  if ( isset( $config['description'] ) ) {
132  return htmlspecialchars( $config['description'] );
133  }
134  return '';
135  }
136 
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'] );
157  }
158  if ( isset( $config['public'] ) && $config['public'] ) {
159  $this->configItems['public'][$name] = $config;
160  } else {
161  $this->configItems['private'][$name] = $config;
162  }
163  }
164 
172  public function isEmpty( $includePrivate = false ) {
173  if ( $includePrivate ) {
174  return empty( $this->configItems['private'] ) &&
175  empty( $this->configItems[ 'public'] );
176  }
177  return empty( $this->configItems['public'] );
178  }
179 
189  public function salvage( SalvageableService $other ) {
190  Assert::parameterType( self::class, $other, '$other' );
191 
192  foreach ( $other->configItems['public'] as $name => $otherConfig ) {
193  if ( isset( $this->configItems['public'][$name] ) ) {
194  continue;
195  }
196 
197  $this->add( $name, $otherConfig );
198  }
199  foreach ( $other->configItems['private'] as $name => $otherConfig ) {
200  if ( isset( $this->configItems['private'][$name] ) ) {
201  continue;
202  }
203 
204  $this->add( $name, $otherConfig );
205  }
206 
207  // disable $other
208  $other->configItems = [];
209  }
210 }
MediaWiki\Config\ConfigRepository\getAll
getAll()
Returns an array of all configuration items saved in this ConfigRepository.
Definition: ConfigRepository.php:88
MediaWiki\Config\ConfigRepository\__construct
__construct(\ConfigFactory $configFactory)
Definition: ConfigRepository.php:46
MediaWiki\Config\ConfigRepository\getValueOf
getValueOf( $name)
Returns the current value of the configuration option.
Definition: ConfigRepository.php:109
MediaWiki\Config\ConfigRepository\salvage
salvage(SalvageableService $other)
Re-uses existing Cache objects from $other.
Definition: ConfigRepository.php:189
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
MediaWiki\Config\ConfigRepository\has
has( $name, $alsoPrivate=false)
Returns true, if this repository contains a configuration with a specific name.
Definition: ConfigRepository.php:57
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Config\ConfigRepository\getPublic
getPublic()
Returns an array of all public configuration options saved in this ConfigRepository.
Definition: ConfigRepository.php:97
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
Wikimedia\Services\SalvageableService
SalvageableService defines an interface for services that are able to salvage state from a previous i...
Definition: SalvageableService.php:35
MediaWiki\Config\ConfigRepository\isEmpty
isEmpty( $includePrivate=false)
Returns true, if there're no elements in this instance, otherwise false.
Definition: ConfigRepository.php:172
MediaWiki\Config\ConfigRepository\$configItems
array $configItems
Definition: ConfigRepository.php:38
MediaWiki\Config
Definition: ConfigRepository.php:23
MediaWiki\Config\ConfigRepository
Object which holds currently registered configuration options.
Definition: ConfigRepository.php:33
MediaWiki\Config\ConfigRepository\getDescriptionOf
getDescriptionOf( $name)
Returns the description of the given config option, This can be either a localized description,...
Definition: ConfigRepository.php:126
MediaWiki\Config\ConfigRepository\$configFactory
ConfigFactory $configFactory
Definition: ConfigRepository.php:35
MediaWiki\$config
Config $config
Definition: MediaWiki.php:43
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ConfigFactory
Factory class to create Config objects.
Definition: ConfigFactory.php:31
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
MediaWiki\Config\ConfigRepository\add
add( $name, array $config)
Adds the definition of a configuration to this repository.
Definition: ConfigRepository.php:152