MediaWiki REL1_33
ConfigFactory.php
Go to the documentation of this file.
1<?php
2
25
32
37 protected $factoryFunctions = [];
38
44 protected $configs = [];
45
51 public static function getDefaultInstance() {
52 return \MediaWiki\MediaWikiServices::getInstance()->getConfigFactory();
53 }
54
66 public function salvage( SalvageableService $other ) {
67 Assert::parameterType( self::class, $other, '$other' );
68
70 foreach ( $other->factoryFunctions as $name => $otherFunc ) {
71 if ( !isset( $this->factoryFunctions[$name] ) ) {
72 continue;
73 }
74
75 // if the callback function is the same, salvage the Cache object
76 // XXX: Closures are never equal!
77 if ( isset( $other->configs[$name] )
78 && $this->factoryFunctions[$name] == $otherFunc
79 ) {
80 $this->configs[$name] = $other->configs[$name];
81 unset( $other->configs[$name] );
82 }
83 }
84
85 // disable $other
86 $other->factoryFunctions = [];
87 $other->configs = [];
88 }
89
93 public function getConfigNames() {
94 return array_keys( $this->factoryFunctions );
95 }
96
106 public function register( $name, $callback ) {
107 if ( !is_callable( $callback ) && !( $callback instanceof Config ) ) {
108 if ( is_array( $callback ) ) {
109 $callback = '[ ' . implode( ', ', $callback ) . ' ]';
110 } elseif ( is_object( $callback ) ) {
111 $callback = 'instanceof ' . get_class( $callback );
112 }
113 throw new InvalidArgumentException( 'Invalid callback \'' . $callback . '\' provided' );
114 }
115
116 unset( $this->configs[$name] );
117 $this->factoryFunctions[$name] = $callback;
118 }
119
129 public function makeConfig( $name ) {
130 if ( !isset( $this->configs[$name] ) ) {
131 $key = $name;
132 if ( !isset( $this->factoryFunctions[$key] ) ) {
133 $key = '*';
134 }
135 if ( !isset( $this->factoryFunctions[$key] ) ) {
136 throw new ConfigException( "No registered builder available for $name." );
137 }
138
139 if ( $this->factoryFunctions[$key] instanceof Config ) {
140 $conf = $this->factoryFunctions[$key];
141 } else {
142 $conf = call_user_func( $this->factoryFunctions[$key], $this );
143 }
144
145 if ( $conf instanceof Config ) {
146 $this->configs[$name] = $conf;
147 } else {
148 throw new UnexpectedValueException( "The builder for $name returned a non-Config object." );
149 }
150 }
151
152 return $this->configs[$name];
153 }
154
155}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Factory class to create Config objects.
static getDefaultInstance()
salvage(SalvageableService $other)
Re-uses existing Cache objects from $other.
array $factoryFunctions
Map of config name => callback.
array $configs
Config objects that have already been created name => Config object.
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
Interface for configuration instances.
Definition Config.php:28
SalvageableService defines an interface for services that are able to salvage state from a previous i...
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))