mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-30 18:14:21 +00:00
32 lines
565 B
PHP
32 lines
565 B
PHP
|
<?php
|
||
|
|
||
|
namespace MediaWiki\Extension\Gadgets;
|
||
|
|
||
|
use InvalidArgumentException;
|
||
|
|
||
|
/**
|
||
|
* @internal For use in tests.
|
||
|
*/
|
||
|
class StaticGadgetRepo extends GadgetRepo {
|
||
|
|
||
|
/**
|
||
|
* @var Gadget[]
|
||
|
*/
|
||
|
private array $gadgets;
|
||
|
|
||
|
public function __construct( array $gadgets ) {
|
||
|
$this->gadgets = $gadgets;
|
||
|
}
|
||
|
|
||
|
public function getGadgetIds(): array {
|
||
|
return array_keys( $this->gadgets );
|
||
|
}
|
||
|
|
||
|
public function getGadget( string $id ): Gadget {
|
||
|
if ( !array_key_exists( $id, $this->gadgets ) ) {
|
||
|
throw new InvalidArgumentException();
|
||
|
}
|
||
|
return $this->gadgets[$id];
|
||
|
}
|
||
|
}
|