26use InvalidArgumentException;
27use Wikimedia\ObjectFactory\ObjectFactory;
35 private const SKIP_BY_SITECONFIG = 1;
36 private const SKIP_BY_REGISTER = 2;
43 private $factoryFunctions = [];
50 private $displayNames = [];
54 private $objectFactory;
70 public function __construct( ObjectFactory $objectFactory, array $skipSkins ) {
71 $this->objectFactory = $objectFactory;
72 $this->skipSkins = array_fill_keys( $skipSkins, self::SKIP_BY_SITECONFIG );
90 public function register( $name, $displayName, $spec, ?
bool $skippable = null ) {
91 if ( !is_callable( $spec ) ) {
92 if ( is_array( $spec ) ) {
93 if ( !isset( $spec[
'args'] ) ) {
100 throw new InvalidArgumentException(
'Invalid callback provided' );
103 $this->factoryFunctions[$name] = $spec;
104 $this->displayNames[$name] = $displayName;
107 if ( ( $this->skipSkins[$name] ??
null ) !== self::SKIP_BY_SITECONFIG ) {
108 if ( $skippable ===
true ) {
109 $this->skipSkins[$name] = self::SKIP_BY_REGISTER;
112 unset( $this->skipSkins[$name] );
125 return $this->displayNames;
136 if ( !isset( $this->factoryFunctions[$name] ) ) {
137 throw new SkinException(
"No registered builder available for $name." );
140 return $this->objectFactory->createObject(
141 $this->factoryFunctions[$name],
143 'allowCallable' =>
true,
144 'assertClass' => Skin::class,
162 foreach ( $this->skipSkins as $name => $_ ) {
163 unset( $skins[$name] );
178 return $this->displayNames;
193 $options = $skin->getOptions();
199class_alias( SkinFactory::class,
'SkinFactory' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.