MediaWiki  1.34.0
ExternalStoreMedium.php
Go to the documentation of this file.
1 <?php
24 use Psr\Log\LoggerAwareInterface;
25 use Psr\Log\LoggerInterface;
26 use Psr\Log\NullLogger;
27 
38 abstract class ExternalStoreMedium implements LoggerAwareInterface {
40  protected $params = [];
42  protected $dbDomain;
45 
47  protected $logger;
48 
55  public function __construct( array $params ) {
56  $this->params = $params;
57  if ( isset( $params['domain'] ) ) {
58  $this->dbDomain = $params['domain'];
59  $this->isDbDomainExplicit = empty( $params['isDomainImplicit'] );
60  } else {
61  throw new InvalidArgumentException( 'Missing DB "domain" parameter.' );
62  }
63 
64  $this->logger = $params['logger'] ?? new NullLogger();
65  }
66 
67  public function setLogger( LoggerInterface $logger ) {
68  $this->logger = $logger;
69  }
70 
78  abstract public function fetchFromURL( $url );
79 
86  public function batchFetchFromURLs( array $urls ) {
87  $retval = [];
88  foreach ( $urls as $url ) {
89  $data = $this->fetchFromURL( $url );
90  // Dont return when false to allow for simpler implementations
91  if ( $data !== false ) {
92  $retval[$url] = $data;
93  }
94  }
95 
96  return $retval;
97  }
98 
107  abstract public function store( $location, $data );
108 
116  public function isReadOnly( $location ) {
117  return false;
118  }
119 }
ExternalStoreMedium
Key/value blob storage for a particular storage medium type (e.g.
Definition: ExternalStoreMedium.php:38
ExternalStoreMedium\setLogger
setLogger(LoggerInterface $logger)
Definition: ExternalStoreMedium.php:67
ExternalStoreMedium\$params
array $params
Usage context options for this instance.
Definition: ExternalStoreMedium.php:40
ExternalStoreMedium\batchFetchFromURLs
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
Definition: ExternalStoreMedium.php:86
ExternalStoreMedium\$dbDomain
string $dbDomain
Default database domain to store content under.
Definition: ExternalStoreMedium.php:42
ExternalStoreMedium\__construct
__construct(array $params)
Definition: ExternalStoreMedium.php:55
ExternalStoreMedium\isReadOnly
isReadOnly( $location)
Check if a given location is read-only.
Definition: ExternalStoreMedium.php:116
ExternalStoreMedium\store
store( $location, $data)
Insert a data item into a given location.
ExternalStoreMedium\$logger
LoggerInterface $logger
Definition: ExternalStoreMedium.php:47
ExternalStoreMedium\fetchFromURL
fetchFromURL( $url)
Fetch data from given external store URL.
ExternalStoreMedium\$isDbDomainExplicit
bool $isDbDomainExplicit
Whether this was factoried with an explicit DB domain.
Definition: ExternalStoreMedium.php:44