*/ private $factoryFunctions = []; /** * Map of name => fallback human-readable name, used when the 'skinname-' message is not * available * * @var array */ private $displayNames = []; /** * @var ObjectFactory */ private $objectFactory; /** * @internal For ServiceWiring only * * @param ObjectFactory $objectFactory */ public function __construct( ObjectFactory $objectFactory ) { $this->objectFactory = $objectFactory; } /** * Register a new Skin factory function. * * Will override if it's already registered. * * @param string $name Internal skin name. Should be all-lowercase (technically doesn't have * to be, but doing so would change the case of i18n message keys). * @param string $displayName For backwards-compatibility with old skin loading system. This is * the text used as skin's human-readable name when the 'skinname-' message is not * available. * @param array|callable $spec Callback that takes the skin name as an argument, or * object factory spec specifying how to create the skin * @throws InvalidArgumentException If an invalid callback is provided */ public function register( $name, $displayName, $spec ) { if ( !is_callable( $spec ) ) { if ( is_array( $spec ) ) { if ( !isset( $spec['args'] ) ) { // make sure name option is set: $spec['args'] = [ [ 'name' => $name ] ]; } } else { throw new InvalidArgumentException( 'Invalid callback provided' ); } } $this->factoryFunctions[$name] = $spec; $this->displayNames[$name] = $displayName; } /** * Returns an associative array of: * skin name => human readable name * * @return array */ public function getSkinNames() { return $this->displayNames; } /** * Create a given Skin using the registered callback for $name. * @param string $name Name of the skin you want * @throws SkinException If a factory function isn't registered for $name * @return Skin */ public function makeSkin( $name ) { if ( !isset( $this->factoryFunctions[$name] ) ) { throw new SkinException( "No registered builder available for $name." ); } return $this->objectFactory->createObject( $this->factoryFunctions[$name], [ 'allowCallable' => true, 'assertClass' => Skin::class, ] ); } }