MediaWiki  1.34.0
OATHAuth.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Config;
8 
14 class OATHAuth {
15  const AUTHENTICATED_OVER_2FA = 'OATHAuthAuthenticatedOver2FA';
16 
20  protected $config;
24  protected $dbLBFactory;
25 
29  protected $modules = [];
30 
35  public function __construct( $config, $dbLBFactory ) {
36  $this->config = $config;
37  $this->dbLBFactory = $dbLBFactory;
38  }
39 
44  public function getModuleByKey( $key ) {
45  $this->collectModules();
46  if ( isset( $this->modules[$key] ) ) {
47  $module = call_user_func_array( $this->modules[$key], [] );
48  if ( $module instanceof IModule === false ) {
49  return null;
50  }
51  return $module;
52  }
53 
54  return null;
55  }
56 
62  public function getAllModules() {
63  $this->collectModules();
64  $modules = [];
65  foreach ( $this->modules as $key => $callback ) {
66  $module = $this->getModuleByKey( $key );
67  if ( $module === null || !( $module instanceof IModule ) ) {
68  continue;
69  }
70  $modules[$key] = $module;
71  }
72  return $modules;
73  }
74 
75  private function collectModules() {
76  $this->modules = ExtensionRegistry::getInstance()->getAttribute( 'OATHAuthModules' );
77  }
78 }
MediaWiki\Extension\OATHAuth\OATHAuth\$dbLBFactory
LBFactory $dbLBFactory
Definition: OATHAuth.php:24
ExtensionRegistry
ExtensionRegistry class.
Definition: ExtensionRegistry.php:18
MediaWiki\Extension\OATHAuth\OATHAuth\AUTHENTICATED_OVER_2FA
const AUTHENTICATED_OVER_2FA
Definition: OATHAuth.php:15
MediaWiki\Extension\OATHAuth\OATHAuth\collectModules
collectModules()
Definition: OATHAuth.php:75
MediaWiki\Extension\OATHAuth\OATHAuth\$config
Config $config
Definition: OATHAuth.php:20
ExtensionRegistry\getInstance
static getInstance()
Definition: ExtensionRegistry.php:106
Config
Interface for configuration instances.
Definition: Config.php:28
MediaWiki\Extension\OATHAuth\OATHAuth
Definition: OATHAuth.php:14
MediaWiki\Extension\OATHAuth\OATHAuth\__construct
__construct( $config, $dbLBFactory)
Definition: OATHAuth.php:35
MediaWiki\Extension\OATHAuth\OATHAuth\getAllModules
getAllModules()
Get all modules registered on the wiki.
Definition: OATHAuth.php:62
MediaWiki\Extension\OATHAuth\OATHAuth\getModuleByKey
getModuleByKey( $key)
Definition: OATHAuth.php:44
MediaWiki\Extension\OATHAuth\OATHAuth\$modules
array $modules
Definition: OATHAuth.php:29
MediaWiki\Extension\OATHAuth
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:40
MediaWiki\Extension\OATHAuth\IModule
Definition: IModule.php:9