MediaWiki  master
MediaWiki\Config\ServiceOptions Class Reference

A class for passing options to services. More...

Public Member Functions

 __construct (array $keys,... $sources)
 
 assertRequiredOptions (array $expectedKeys)
 Assert that the list of options provided in this instance exactly match $expectedKeys, without regard for order. More...
 
 get ( $key)
 

Private Attributes

 $keys = []
 
 $options = []
 

Detailed Description

A class for passing options to services.

It can be constructed from a Config, and in practice most options will be taken from site configuration, but they don't have to be. The options passed are copied and will not reflect subsequent updates to site configuration (assuming they're not objects).

Services that take this type as a parameter to their constructor should specify a list of the keys they expect to receive in an array. The convention is to make it a public static variable called $constructorOptions. (When we drop HHVM support – see T192166 – it should become a const.) In the constructor, they should call assertRequiredOptions() to make sure that they weren't passed too few or too many options. This way it's clear what each class depends on, and that it's getting passed the correct set of options. (This means there are no optional options. This makes sense for services, since they shouldn't be constructed by outside code.)

Since
1.34

Definition at line 25 of file ServiceOptions.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Config\ServiceOptions::__construct ( array  $keys,
  $sources 
)
Parameters
string[]$keys Which keys to extract from $sources
Config|array...$sources Each source is either a Config object or an array. If the same key is present in two sources, the first one takes precedence. Keys that are not in $keys are ignored.
Exceptions
InvalidArgumentExceptionif one of $keys is not found in any of $sources

Definition at line 36 of file ServiceOptions.php.

References MediaWiki\Config\ServiceOptions\$keys, $source, as, and options().

Member Function Documentation

◆ assertRequiredOptions()

MediaWiki\Config\ServiceOptions::assertRequiredOptions ( array  $expectedKeys)

◆ get()

MediaWiki\Config\ServiceOptions::get (   $key)
Parameters
string$key
Returns
mixed

Definition at line 84 of file ServiceOptions.php.

References options().

Referenced by Parser\__construct(), MWLBFactory\applyDefaultConfig(), and MWLBFactory\initServerInfo().

Member Data Documentation

◆ $keys

MediaWiki\Config\ServiceOptions::$keys = []
private

Definition at line 26 of file ServiceOptions.php.

Referenced by MediaWiki\Config\ServiceOptions\__construct().

◆ $options

MediaWiki\Config\ServiceOptions::$options = []
private

Definition at line 27 of file ServiceOptions.php.


The documentation for this class was generated from the following file: