2015-07-18 22:40:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class GadgetRepo {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var GadgetRepo|null
|
|
|
|
*/
|
|
|
|
private static $instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ids of the gadgets provided by this repository
|
|
|
|
*
|
2015-08-03 06:37:32 +00:00
|
|
|
* It's possible this could be out of sync with what
|
|
|
|
* getGadget() will return due to caching
|
|
|
|
*
|
2015-07-18 22:40:42 +00:00
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
abstract public function getGadgetIds();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Gadget object for a given gadget id
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
* @return Gadget
|
|
|
|
*/
|
|
|
|
abstract public function getGadget( $id );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of gadgets sorted by category
|
|
|
|
*
|
|
|
|
* @return array array( 'category' => array( 'name' => $gadget ) )
|
|
|
|
*/
|
|
|
|
public function getStructuredList() {
|
|
|
|
$list = array();
|
|
|
|
foreach ( $this->getGadgetIds() as $id ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
try {
|
|
|
|
$gadget = $this->getGadget( $id );
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-18 22:40:42 +00:00
|
|
|
$list[$gadget->getCategory()][$gadget->getName()] = $gadget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-08-03 06:37:32 +00:00
|
|
|
* Get the configured default GadgetRepo.
|
2015-07-18 22:40:42 +00:00
|
|
|
*
|
|
|
|
* @return GadgetRepo
|
|
|
|
*/
|
|
|
|
public static function singleton() {
|
|
|
|
if ( self::$instance === null ) {
|
2015-08-03 06:37:32 +00:00
|
|
|
global $wgGadgetsRepoClass; // @todo use Config here
|
|
|
|
self::$instance = new $wgGadgetsRepoClass();
|
2015-07-18 22:40:42 +00:00
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should only be used by unit tests
|
|
|
|
*
|
|
|
|
* @param GadgetRepo|null $repo
|
|
|
|
*/
|
|
|
|
public static function setSingleton( $repo = null ) {
|
|
|
|
self::$instance = $repo;
|
|
|
|
}
|
|
|
|
}
|