Vector
Vector is a skin for MediaWiki. Vector has been the default skin on all Wikimedia wikis since 2010.
Loading...
Searching...
No Matches
MediaWiki\Skins\Vector\FeatureManagement\FeatureManager Class Reference

Public Member Functions

 registerFeature (string $feature, $requirements)
 Register a feature and its requirements.
 
 getFeatureBodyClass ()
 Return a list of classes that should be added to the body tag.
 
 isFeatureEnabled (string $feature)
 Gets whether the feature's requirements are met.
 
 registerRequirement (Requirement $requirement)
 Register a complex {.
 
 registerSimpleRequirement (string $name, bool $isMet)
 Register a {.
 
 isRequirementMet (string $name)
 Gets whether the requirement is met.
 

Member Function Documentation

◆ getFeatureBodyClass()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::getFeatureBodyClass ( )

Return a list of classes that should be added to the body tag.

Returns
array

◆ isFeatureEnabled()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::isFeatureEnabled ( string $feature)

Gets whether the feature's requirements are met.

Parameters
string$feature
Returns
bool
Exceptions

InvalidArgumentException If the feature isn't registered

◆ isRequirementMet()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::isRequirementMet ( string $name)

Gets whether the requirement is met.

Parameters
string$nameThe name of the requirement
Returns
bool
Exceptions

InvalidArgumentException If the requirement isn't registered

◆ registerFeature()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::registerFeature ( string $feature,
$requirements )

Register a feature and its requirements.

Essentially, a "feature" is a friendly (hopefully) name for some component, however big or small, that has some requirements. A feature manager allows us to decouple the component's logic from its requirements, allowing them to vary independently. Moreover, the use of friendly names wherever possible allows us to define a common language with our non-technical colleagues.

$featureManager->registerFeature( 'featureA', 'requirementA' );

defines the "featureA" feature, which is enabled when the "requirementA" requirement is met.

$featureManager->registerFeature( 'featureB', [ 'requirementA', 'requirementB' ] );

defines the "featureB" feature, which is enabled when the "requirementA" and "requirementB" requirements are met. Note well that the feature is only enabled when all requirements are met, i.e. the requirements are evaluated in order and logically ANDed together.

Parameters
string$featureThe name of the feature
string | array$requirementsThe feature's requirements. As above, you can define a feature that requires a single requirement via the shorthand
$featureManager->registerFeature( 'feature', 'requirementA' );
// Equivalent to $featureManager->registerFeature( 'feature', [ 'requirementA' ] );
Exceptions

LogicException If the feature is already registered

Exceptions

Wikimedia\Assert\ParameterAssertionException If the feature's requirements aren't the name of a single requirement or a list of requirements

Exceptions

InvalidArgumentException If the feature references a requirement that isn't registered

◆ registerRequirement()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::registerRequirement ( Requirement $requirement)

Register a complex {.

See also
Requirement}.

A complex requirement is one that depends on object that may or may not be fully loaded while the application is booting, e.g. see User::isSafeToLoad.

Such requirements are expected to be registered during a hook that is run early on in the application lifecycle, e.g. the BeforePerformAction and APIBeforeMain hooks.

Parameters
Requirement$requirement
Exceptions

LogicException If the requirement has already been registered

◆ registerSimpleRequirement()

MediaWiki\Skins\Vector\FeatureManagement\FeatureManager::registerSimpleRequirement ( string $name,
bool $isMet )

Register a {.

See also
SimpleRequirement}.

A requirement is some condition of the application state that a feature requires to be true or false.

Parameters
string$nameThe name of the requirement
bool$isMetWhether the requirement is met
Exceptions

LogicException If the requirement has already been registered


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