4 use Psr\Log\LoggerAwareInterface;
5 use Psr\Log\LoggerInterface;
6 use Psr\Log\NullLogger;
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 if ( $protoLowercase ===
'db' ) {
81 $class =
'ExternalStoreDB';
83 $class =
'ExternalStore' . ucfirst( $proto );
85 if ( isset( $params[
'wiki'] ) ) {
86 $params += [
'domain' => $params[
'wiki'] ];
88 if ( !isset( $params[
'domain'] ) || $params[
'domain'] ===
false ) {
89 $params[
'domain'] = $this->localDomainId;
90 $params[
'isDomainImplicit'] =
true;
94 if ( $protoLowercase ===
'db' ) {
95 $params[
'lbFactory'] = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
96 } elseif ( $protoLowercase ===
'mwstore' ) {
97 $params[
'fbGroup'] = MediaWikiServices::getInstance()->getFileBackendGroup();
99 $params[
'logger'] = $this->logger;
101 if ( !class_exists( $class ) ) {
106 return new $class( $params );
123 [ $proto,
$path ] = self::splitStorageUrl( $url );
128 return $this->
getStore( $proto, $params );
140 [ , $location ] = self::splitStorageUrl( $url );
141 if ( $location ==
'' ) {
155 $urlsByProtocol = [];
156 foreach ( $urls as $url ) {
157 [ $proto, ] = self::splitStorageUrl( $url );
158 $urlsByProtocol[$proto][] = $url;
161 return $urlsByProtocol;
169 private static function splitStorageUrl( $storeUrl ) {
170 $parts = explode(
'://', $storeUrl );
171 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.