MediaWiki
REL1_22
|
00001 <?php 00034 class ApiModuleManager extends ContextSource { 00035 00036 private $mParent; 00037 private $mInstances = array(); 00038 private $mGroups = array(); 00039 private $mModules = array(); 00040 00045 public function __construct( ApiBase $parentModule ) { 00046 $this->mParent = $parentModule; 00047 } 00048 00054 public function addModules( array $modules, $group ) { 00055 foreach ( $modules as $name => $class ) { 00056 $this->addModule( $name, $group, $class ); 00057 } 00058 } 00059 00069 public function addModule( $name, $group, $class ) { 00070 $this->mGroups[$group] = null; 00071 $this->mModules[$name] = array( $group, $class ); 00072 } 00073 00081 public function getModule( $moduleName, $group = null, $ignoreCache = false ) { 00082 if ( !isset( $this->mModules[$moduleName] ) ) { 00083 return null; 00084 } 00085 $grpCls = $this->mModules[$moduleName]; 00086 if ( $group !== null && $grpCls[0] !== $group ) { 00087 return null; 00088 } 00089 if ( !$ignoreCache && isset( $this->mInstances[$moduleName] ) ) { 00090 // already exists 00091 return $this->mInstances[$moduleName]; 00092 } else { 00093 // new instance 00094 $class = $grpCls[1]; 00095 $instance = new $class ( $this->mParent, $moduleName ); 00096 if ( !$ignoreCache ) { 00097 // cache this instance in case it is needed later 00098 $this->mInstances[$moduleName] = $instance; 00099 } 00100 return $instance; 00101 } 00102 } 00103 00109 public function getNames( $group = null ) { 00110 if ( $group === null ) { 00111 return array_keys( $this->mModules ); 00112 } 00113 $result = array(); 00114 foreach ( $this->mModules as $name => $grpCls ) { 00115 if ( $grpCls[0] === $group ) { 00116 $result[] = $name; 00117 } 00118 } 00119 return $result; 00120 } 00121 00127 public function getNamesWithClasses( $group = null ) { 00128 $result = array(); 00129 foreach ( $this->mModules as $name => $grpCls ) { 00130 if ( $group === null || $grpCls[0] === $group ) { 00131 $result[$name] = $grpCls[1]; 00132 } 00133 } 00134 return $result; 00135 } 00136 00143 public function isDefined( $moduleName, $group = null ) { 00144 if ( isset( $this->mModules[$moduleName] ) ) { 00145 return $group === null || $this->mModules[$moduleName][0] === $group; 00146 } else { 00147 return false; 00148 } 00149 } 00150 00156 public function getModuleGroup( $moduleName ) { 00157 if ( isset( $this->mModules[$moduleName] ) ) { 00158 return $this->mModules[$moduleName][0]; 00159 } else { 00160 return null; 00161 } 00162 } 00163 00168 public function getGroups() { 00169 return array_keys( $this->mGroups ); 00170 } 00171 }