4use Psr\Log\LoggerAwareInterface;
5use Psr\Log\LoggerInterface;
18 private $writeBaseUrls;
20 private $localDomainId;
32 array $externalStores,
34 string $localDomainId,
35 LoggerInterface $logger =
null
37 $this->protocols = array_map(
'strtolower', $externalStores );
38 $this->writeBaseUrls = $defaultStores;
39 $this->localDomainId = $localDomainId;
40 $this->logger = $logger ?:
new NullLogger();
43 public function setLogger( LoggerInterface $logger ) {
44 $this->logger = $logger;
52 return $this->protocols;
60 return $this->writeBaseUrls;
76 $cacheKey = $proto .
':' . json_encode(
$params );
77 if ( isset( $this->stores[$cacheKey] ) ) {
78 return $this->stores[$cacheKey];
80 $protoLowercase = strtolower( $proto );
81 if ( !$this->protocols || !in_array( $protoLowercase, $this->protocols ) ) {
85 if ( $protoLowercase ===
'db' ) {
86 $class =
'ExternalStoreDB';
88 $class =
'ExternalStore' . ucfirst( $proto );
90 if ( isset(
$params[
'wiki'] ) ) {
93 if ( !isset(
$params[
'domain'] ) ||
$params[
'domain'] ===
false ) {
94 $params[
'domain'] = $this->localDomainId;
95 $params[
'isDomainImplicit'] =
true;
99 if ( $protoLowercase ===
'db' ) {
100 $params[
'lbFactory'] = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
101 } elseif ( $protoLowercase ===
'mwstore' ) {
102 $params[
'fbGroup'] = MediaWikiServices::getInstance()->getFileBackendGroup();
104 $params[
'logger'] = $this->logger;
106 if ( !class_exists( $class ) ) {
111 $this->stores[$cacheKey] =
new $class(
$params );
112 return $this->stores[$cacheKey];
129 [ $proto,
$path ] = self::splitStorageUrl(
$url );
146 [ , $location ] = self::splitStorageUrl(
$url );
147 if ( $location ==
'' ) {
161 $urlsByProtocol = [];
162 foreach ( $urls as
$url ) {
163 [ $proto, ] = self::splitStorageUrl(
$url );
164 $urlsByProtocol[$proto][] =
$url;
167 return $urlsByProtocol;
175 private static function splitStorageUrl( $storeUrl ) {
176 $parts = explode(
'://', $storeUrl );
177 if ( count( $parts ) != 2 || $parts[0] ===
'' || $parts[1] ===
'' ) {
array $params
The job parameters.
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.