MediaWiki  1.34.0
SkinFactory.php
Go to the documentation of this file.
1 <?php
2 
29 class SkinFactory {
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 }
SkinFactory\$displayNames
array $displayNames
Map of name => fallback human-readable name, used when the 'skinname-<skin>' message is not available...
Definition: SkinFactory.php:42
SkinFactory\makeSkin
makeSkin( $name)
Create a given Skin using the registered callback for $name.
Definition: SkinFactory.php:82
SkinFactory\getSkinNames
getSkinNames()
Returns an associative array of: skin name => human readable name.
Definition: SkinFactory.php:71
SkinFactory\$factoryFunctions
array $factoryFunctions
Map of name => callback.
Definition: SkinFactory.php:35
SkinFactory
Factory class to create Skin objects.
Definition: SkinFactory.php:29
SkinException
Exceptions for skin-related failures.
Definition: SkinException.php:28
Skin
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:38