Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / externalstore / ExternalStoreFactory.php
1 <?php
2 /**
3 * @defgroup ExternalStorage ExternalStorage
4 */
5
6 /**
7 * @ingroup ExternalStorage
8 */
9 class ExternalStoreFactory {
10
11 /**
12 * @var array
13 */
14 private $externalStores;
15
16 /**
17 * @param array $externalStores See $wgExternalStores
18 */
19 public function __construct( array $externalStores ) {
20 $this->externalStores = array_map( 'strtolower', $externalStores );
21 }
22
23 /**
24 * Get an external store object of the given type, with the given parameters
25 *
26 * @param string $proto Type of external storage, should be a value in $wgExternalStores
27 * @param array $params Associative array of ExternalStoreMedium parameters
28 * @return ExternalStoreMedium|bool The store class or false on error
29 */
30 public function getStoreObject( $proto, array $params = [] ) {
31 if ( !$this->externalStores || !in_array( strtolower( $proto ), $this->externalStores ) ) {
32 // Protocol not enabled
33 return false;
34 }
35
36 $class = 'ExternalStore' . ucfirst( $proto );
37
38 // Any custom modules should be added to $wgAutoLoadClasses for on-demand loading
39 return class_exists( $class ) ? new $class( $params ) : false;
40 }
41
42 }