24use 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] );
122 return $this->displayNames;
133 if ( !isset( $this->factoryFunctions[$name] ) ) {
134 throw new SkinException(
"No registered builder available for $name." );
137 return $this->objectFactory->createObject(
138 $this->factoryFunctions[$name],
140 'allowCallable' =>
true,
141 'assertClass' => Skin::class,
159 foreach ( $this->skipSkins as $name => $_ ) {
160 unset( $skins[$name] );
175 return $this->displayNames;
190 $options = $skin->getOptions();
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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)