summaryrefslogtreecommitdiff
path: root/www/wiki/includes/externalstore/ExternalStoreFactory.php
blob: 940fb2e20c4c608f06b8b0839c29e5ef7a531a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
 * @defgroup ExternalStorage ExternalStorage
 */

/**
 * @ingroup ExternalStorage
 */
class ExternalStoreFactory {

	/**
	 * @var array
	 */
	private $externalStores;

	/**
	 * @param array $externalStores See $wgExternalStores
	 */
	public function __construct( array $externalStores ) {
		$this->externalStores = array_map( 'strtolower', $externalStores );
	}

	/**
	 * Get an external store object of the given type, with the given parameters
	 *
	 * @param string $proto Type of external storage, should be a value in $wgExternalStores
	 * @param array $params Associative array of ExternalStoreMedium parameters
	 * @return ExternalStoreMedium|bool The store class or false on error
	 */
	public function getStoreObject( $proto, array $params = [] ) {
		if ( !$this->externalStores || !in_array( strtolower( $proto ), $this->externalStores ) ) {
			// Protocol not enabled
			return false;
		}

		$class = 'ExternalStore' . ucfirst( $proto );

		// Any custom modules should be added to $wgAutoLoadClasses for on-demand loading
		return class_exists( $class ) ? new $class( $params ) : false;
	}

}