24 use Wikimedia\ObjectFactory\ObjectFactory;
32 private const SKIP_BY_SITECONFIG = 1;
33 private const SKIP_BY_REGISTER = 2;
40 private $factoryFunctions = [];
47 private $displayNames = [];
51 private $objectFactory;
67 public function __construct( ObjectFactory $objectFactory, array $skipSkins ) {
68 $this->objectFactory = $objectFactory;
69 $this->skipSkins = array_fill_keys( $skipSkins, self::SKIP_BY_SITECONFIG );
87 public function register( $name, $displayName, $spec,
bool $skippable = null ) {
88 if ( !is_callable( $spec ) ) {
89 if ( is_array( $spec ) ) {
90 if ( !isset( $spec[
'args'] ) ) {
97 throw new InvalidArgumentException(
'Invalid callback provided' );
100 $this->factoryFunctions[$name] = $spec;
101 $this->displayNames[$name] = $displayName;
104 if ( ( $this->skipSkins[$name] ??
null ) !== self::SKIP_BY_SITECONFIG ) {
105 if ( $skippable ===
true ) {
106 $this->skipSkins[$name] = self::SKIP_BY_REGISTER;
109 unset( $this->skipSkins[$name] );
121 return $this->displayNames;
132 if ( !isset( $this->factoryFunctions[$name] ) ) {
133 throw new SkinException(
"No registered builder available for $name." );
136 return $this->objectFactory->createObject(
137 $this->factoryFunctions[$name],
139 'allowCallable' =>
true,
140 'assertClass' => Skin::class,
158 foreach ( $this->skipSkins as $name => $_ ) {
159 unset( $skins[$name] );
174 return $this->displayNames;
186 $options = $skin->getOptions();
Exceptions for skin-related failures.
Factory class to create Skin objects.
makeSkin( $name)
Create a given Skin using the registered callback for $name.
getInstalledSkins()
Get the list of installed skins.
getSkinNames()
Return an associative array of skin name => human readable name.
getSkinOptions(string $name)
Return options provided for a given skin name.
getAllowedSkins()
Get the list of user-selectable skins.
__construct(ObjectFactory $objectFactory, array $skipSkins)