MediaWiki REL1_33
ApiModuleManager Class Reference

This class holds a list of modules and handles instantiation. More...

Inheritance diagram for ApiModuleManager:
Collaboration diagram for ApiModuleManager:

Public Member Functions

 __construct (ApiBase $parentModule)
 Construct new module manager.
 
 addModule ( $name, $group, $class, $factory=null)
 Add or overwrite a module in this ApiMain instance.
 
 addModules (array $modules, $group)
 Add a list of modules to the manager.
 
 getClassName ( $module)
 Returns the class name of the given module.
 
 getGroups ()
 Get a list of groups this manager contains.
 
 getModule ( $moduleName, $group=null, $ignoreCache=false)
 Get module instance by name, or instantiate it if it does not exist.
 
 getModuleGroup ( $moduleName)
 Returns the group name for the given module.
 
 getNames ( $group=null)
 Get an array of modules in a specific group or all if no group is set.
 
 getNamesWithClasses ( $group=null)
 Create an array of (moduleName => moduleClass) for a specific group or for all.
 
 isDefined ( $moduleName, $group=null)
 Returns true if the specific module is defined at all or in a specific group.
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage().
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID.
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object.
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getTitle ()
 
 getUser ()
 
 getWikiPage ()
 Get the WikiPage object.
 
 msg ( $key)
 Get a Message object with context set Parameters are the same as wfMessage()
 
 setContext (IContextSource $context)
 

Private Member Functions

 instantiateModule ( $name, $class, $factory=null)
 Instantiate the module using the given class or factory function.
 

Private Attributes

null[] $mGroups = []
 
ApiBase[] $mInstances = []
 
array[] $mModules = []
 
ApiBase $mParent
 

Detailed Description

This class holds a list of modules and handles instantiation.

Since
1.21

Definition at line 30 of file ApiModuleManager.php.

Constructor & Destructor Documentation

◆ __construct()

ApiModuleManager::__construct ( ApiBase $parentModule)

Construct new module manager.

Parameters
ApiBase$parentModuleParent module instance will be used during instantiation

Definition at line 53 of file ApiModuleManager.php.

References and().

Member Function Documentation

◆ addModule()

ApiModuleManager::addModule ( $name,
$group,
$class,
$factory = null )

Add or overwrite a module in this ApiMain instance.

Intended for use by extending classes who wish to add their own modules to their lexicon or override the behavior of inherent ones.

Parameters
string$nameThe identifier for this module.
string$groupName of the module group
string$classThe class where this module is implemented.
callable | null$factoryCallback for instantiating the module.
Exceptions
InvalidArgumentException

Definition at line 121 of file ApiModuleManager.php.

References $name, and and().

Referenced by addModules().

◆ addModules()

ApiModuleManager::addModules ( array $modules,
$group )

Add a list of modules to the manager.

Each module is described by a module spec.

Each module spec is an associative array containing at least the 'class' key for the module's class, and optionally a 'factory' key for the factory function to use for the module.

That factory function will be called with two parameters, the parent module (an instance of ApiBase, usually ApiMain) and the name the module was registered under. The return value must be an instance of the class given in the 'class' field.

For backward compatibility, the module spec may also be a simple string containing the module's class name. In that case, the class' constructor will be called with the parent module and module name as parameters, as described above.

Examples for defining module specs:

$modules['foo'] = 'ApiFoo';
$modules['bar'] = [
'class' => ApiBar::class,
'factory' => function( $main, $name ) { ... }
];
$modules['xyzzy'] = [
'class' => ApiXyzzy::class,
'factory' => [ XyzzyFactory::class, 'newApiModule' ]
];
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
Parameters
array$modulesA map of ModuleName => ModuleSpec; The ModuleSpec is either a string containing the module's class name, or an associative array (see above for details).
string$groupWhich group modules belong to (action,format,...)

Definition at line 95 of file ApiModuleManager.php.

References $modules, addModule(), and(), and null.

◆ getClassName()

ApiModuleManager::getClassName ( $module)

Returns the class name of the given module.

Parameters
string$moduleModule name
Returns
string|bool class name or false if the module does not exist
Since
1.24

Definition at line 248 of file ApiModuleManager.php.

References and().

◆ getGroups()

ApiModuleManager::getGroups ( )

Get a list of groups this manager contains.

Returns
array

Definition at line 287 of file ApiModuleManager.php.

References and().

◆ getModule()

ApiModuleManager::getModule ( $moduleName,
$group = null,
$ignoreCache = false )

Get module instance by name, or instantiate it if it does not exist.

Parameters
string$moduleNameModule name
string | null$groupOptionally validate that the module is in a specific group
bool$ignoreCacheIf true, force-creates a new instance and does not cache it
Returns
ApiBase|null The new module instance, or null if failed

Definition at line 151 of file ApiModuleManager.php.

References and(), instantiateModule(), and list.

Referenced by ApiStructureTest\getSubModulePaths().

◆ getModuleGroup()

ApiModuleManager::getModuleGroup ( $moduleName)

Returns the group name for the given module.

Parameters
string$moduleName
Returns
string|null Group name or null if missing

Definition at line 275 of file ApiModuleManager.php.

References and().

◆ getNames()

ApiModuleManager::getNames ( $group = null)

Get an array of modules in a specific group or all if no group is set.

Parameters
string | null$groupOptional group filter
Returns
array List of module names

Definition at line 211 of file ApiModuleManager.php.

References $name, $result, and and().

Referenced by ApiStructureTest\getSubModulePaths().

◆ getNamesWithClasses()

ApiModuleManager::getNamesWithClasses ( $group = null)

Create an array of (moduleName => moduleClass) for a specific group or for all.

Parameters
string | null$groupName of the group to get or null for all
Returns
array Name=>class map

Definition at line 230 of file ApiModuleManager.php.

References $name, and $result.

◆ instantiateModule()

ApiModuleManager::instantiateModule ( $name,
$class,
$factory = null )
private

Instantiate the module using the given class or factory function.

Parameters
string$nameThe identifier for this module.
string$classThe class where this module is implemented.
callable | null$factoryCallback for instantiating the module.
Exceptions
MWException
Returns
ApiBase

Definition at line 188 of file ApiModuleManager.php.

References and().

Referenced by getModule().

◆ isDefined()

ApiModuleManager::isDefined ( $moduleName,
$group = null )

Returns true if the specific module is defined at all or in a specific group.

Parameters
string$moduleNameModule name
string | null$groupGroup name to check against, or null to check all groups,
Returns
bool True if defined

Definition at line 262 of file ApiModuleManager.php.

References and().

Member Data Documentation

◆ $mGroups

null [] ApiModuleManager::$mGroups = []
private

Definition at line 43 of file ApiModuleManager.php.

◆ $mInstances

ApiBase [] ApiModuleManager::$mInstances = []
private

Definition at line 39 of file ApiModuleManager.php.

◆ $mModules

array [] ApiModuleManager::$mModules = []
private

Definition at line 47 of file ApiModuleManager.php.

◆ $mParent

ApiBase ApiModuleManager::$mParent
private

Definition at line 35 of file ApiModuleManager.php.


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