4use Psr\Log\LoggerAwareInterface;
5use Psr\Log\LoggerInterface;
18 private $writeBaseUrls;
20 private $localDomainId;
31 array $externalStores,
33 string $localDomainId,
34 LoggerInterface $logger =
null
36 $this->protocols = array_map(
'strtolower', $externalStores );
37 $this->writeBaseUrls = $defaultStores;
38 $this->localDomainId = $localDomainId;
39 $this->logger = $logger ?:
new NullLogger();
42 public function setLogger( LoggerInterface $logger ) {
43 $this->logger = $logger;
51 return $this->protocols;
59 return $this->writeBaseUrls;
74 public function getStore( $proto, array $params = [] ) {
75 $protoLowercase = strtolower( $proto );
76 if ( !$this->protocols || !in_array( $protoLowercase, $this->protocols ) ) {
80 $class =
'ExternalStore' . ucfirst( $proto );
81 if ( isset( $params[
'wiki'] ) ) {
82 $params += [
'domain' => $params[
'wiki'] ];
84 if ( !isset( $params[
'domain'] ) || $params[
'domain'] ===
false ) {
85 $params[
'domain'] = $this->localDomainId;
86 $params[
'isDomainImplicit'] =
true;
90 if ( $protoLowercase ===
'db' ) {
91 $params[
'lbFactory'] = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
92 } elseif ( $protoLowercase ===
'mwstore' ) {
93 $params[
'fbGroup'] = MediaWikiServices::getInstance()->getFileBackendGroup();
95 $params[
'logger'] = $this->logger;
97 if ( !class_exists( $class ) ) {
102 return new $class( $params );
119 list( $proto,
$path ) = self::splitStorageUrl( $url );
124 return $this->
getStore( $proto, $params );
136 list( , $location ) = self::splitStorageUrl( $url );
137 if ( $location ==
'' ) {
151 $urlsByProtocol = [];
152 foreach ( $urls as $url ) {
153 list( $proto, ) = self::splitStorageUrl( $url );
154 $urlsByProtocol[$proto][] = $url;
157 return $urlsByProtocol;
165 private static function splitStorageUrl( $storeUrl ) {
166 $parts = explode(
'://', $storeUrl );
167 if ( count( $parts ) != 2 || $parts[0] ===
'' || $parts[1] ===
'' ) {
getUrlsByProtocol(array $urls)
setLogger(LoggerInterface $logger)
__construct(array $externalStores, array $defaultStores, string $localDomainId, LoggerInterface $logger=null)
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.
getStoreLocationFromUrl( $url)
Get the location within the appropriate store for a given a URL.