7use Psr\Log\LoggerAwareInterface;
8use Psr\Log\LoggerInterface;
10use Wikimedia\Assert\Assert;
32 array $externalStores,
37 Assert::parameterType(
'string',
$localDomainId,
'$localDomainId' );
39 $this->protocols = array_map(
'strtolower', $externalStores );
40 $this->writeBaseUrls = $defaultStores;
42 $this->logger =
$logger ?:
new NullLogger();
77 public function getStore( $proto, array $params = [] ) {
78 $protoLowercase = strtolower( $proto );
79 if ( !$this->protocols || !in_array( $protoLowercase, $this->protocols ) ) {
83 $class =
'ExternalStore' . ucfirst( $proto );
84 if ( isset( $params[
'wiki'] ) ) {
85 $params += [
'domain' => $params[
'wiki'] ];
87 if ( !isset( $params[
'domain'] ) || $params[
'domain'] ===
false ) {
89 $params[
'isDomainImplicit'] =
true;
93 if ( $protoLowercase ===
'db' ) {
94 $params[
'lbFactory'] = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
95 } elseif ( $protoLowercase ===
'mwstore' ) {
100 if ( !class_exists( $class ) ) {
105 return new $class( $params );
127 return $this->
getStore( $proto, $params );
140 if ( $location ==
'' ) {
154 $urlsByProtocol = [];
155 foreach (
$urls as $url ) {
157 $urlsByProtocol[$proto][] = $url;
160 return $urlsByProtocol;
169 $parts = explode(
'://', $storeUrl );
170 if ( count( $parts ) != 2 || $parts[0] ===
'' || $parts[1] ===
'' ) {
getUrlsByProtocol(array $urls)
setLogger(LoggerInterface $logger)
__construct(array $externalStores, array $defaultStores, $localDomainId, LoggerInterface $logger=null)
string[] $protocols
List of storage access protocols.
string $localDomainId
Default database domain to store content under.
static splitStorageUrl( $storeUrl)
getStore( $proto, array $params=[])
Get an external store object of the given type, with the given parameters.
getStoreForUrl( $url, array $params=[])
Get the ExternalStoreMedium for a given URL.
string[] $writeBaseUrls
List of base storage URLs that define locations for writes.
getStoreLocationFromUrl( $url)
Get the location within the appropriate store for a given a URL.