wiki.techinc.nl/includes/externalstore/ExternalStoreFactory.php
addshore 24b24e493e Introduce ExternalStoreFactory
Change-Id: If0d8f503e3cc9fd83f3b40e2ac8a5f9dc8b7e0ea
2017-11-14 13:22:12 +00:00

42 lines
1.1 KiB
PHP

<?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;
}
}