MediaWiki  master
ExternalStoreMedium.php
Go to the documentation of this file.
1 <?php
21 use Psr\Log\LoggerAwareInterface;
22 use Psr\Log\LoggerInterface;
23 use Psr\Log\NullLogger;
24 
36 abstract class ExternalStoreMedium implements LoggerAwareInterface {
38  protected $params = [];
40  protected $dbDomain;
43 
45  protected $logger;
46 
53  public function __construct( array $params ) {
54  $this->params = $params;
55  if ( isset( $params['domain'] ) ) {
56  $this->dbDomain = $params['domain'];
57  $this->isDbDomainExplicit = empty( $params['isDomainImplicit'] );
58  } else {
59  throw new InvalidArgumentException( 'Missing DB "domain" parameter.' );
60  }
61 
62  $this->logger = $params['logger'] ?? new NullLogger();
63  }
64 
65  public function setLogger( LoggerInterface $logger ) {
66  $this->logger = $logger;
67  }
68 
76  abstract public function fetchFromURL( $url );
77 
84  public function batchFetchFromURLs( array $urls ) {
85  $retval = [];
86  foreach ( $urls as $url ) {
87  $data = $this->fetchFromURL( $url );
88  // Dont return when false to allow for simpler implementations
89  if ( $data !== false ) {
90  $retval[$url] = $data;
91  }
92  }
93 
94  return $retval;
95  }
96 
105  abstract public function store( $location, $data );
106 
114  public function isReadOnly( $location ) {
115  return false;
116  }
117 }
ExternalStoreMedium
Base class for external storage.
Definition: ExternalStoreMedium.php:36
ExternalStoreMedium\setLogger
setLogger(LoggerInterface $logger)
Definition: ExternalStoreMedium.php:65
ExternalStoreMedium\$params
array $params
Usage context options for this instance.
Definition: ExternalStoreMedium.php:38
ExternalStoreMedium\batchFetchFromURLs
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
Definition: ExternalStoreMedium.php:84
ExternalStoreMedium\$dbDomain
string $dbDomain
Default database domain to store content under.
Definition: ExternalStoreMedium.php:40
ExternalStoreMedium\__construct
__construct(array $params)
Definition: ExternalStoreMedium.php:53
ExternalStoreMedium\isReadOnly
isReadOnly( $location)
Check if a given location is read-only.
Definition: ExternalStoreMedium.php:114
ExternalStoreMedium\store
store( $location, $data)
Insert a data item into a given location.
ExternalStoreMedium\$logger
LoggerInterface $logger
Definition: ExternalStoreMedium.php:45
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:42