MediaWiki REL1_34
SkinFactory.php
Go to the documentation of this file.
1<?php
2
30
35 private $factoryFunctions = [];
42 private $displayNames = [];
43
57 public function register( $name, $displayName, $callback ) {
58 if ( !is_callable( $callback ) ) {
59 throw new InvalidArgumentException( 'Invalid callback provided' );
60 }
61 $this->factoryFunctions[$name] = $callback;
62 $this->displayNames[$name] = $displayName;
63 }
64
71 public function getSkinNames() {
72 return $this->displayNames;
73 }
74
82 public function makeSkin( $name ) {
83 if ( !isset( $this->factoryFunctions[$name] ) ) {
84 throw new SkinException( "No registered builder available for $name." );
85 }
86 $skin = call_user_func( $this->factoryFunctions[$name], $name );
87 if ( $skin instanceof Skin ) {
88 return $skin;
89 } else {
90 throw new UnexpectedValueException( "The builder for $name returned a non-Skin object." );
91 }
92 }
93}
Exceptions for skin-related failures.
Factory class to create Skin objects.
makeSkin( $name)
Create a given Skin using the registered callback for $name.
array $factoryFunctions
Map of name => callback.
array $displayNames
Map of name => fallback human-readable name, used when the 'skinname-<skin>' message is not available...
getSkinNames()
Returns an associative array of: skin name => human readable name.
The main skin class which provides methods and properties for all other skins.
Definition Skin.php:38