MediaWiki master
ExternalStoreMedium.php
Go to the documentation of this file.
1<?php
7use Psr\Log\LoggerAwareInterface;
8use Psr\Log\LoggerInterface;
9use Psr\Log\NullLogger;
10
22abstract class ExternalStoreMedium implements LoggerAwareInterface {
24 protected $params = [];
26 protected $dbDomain;
29
31 protected $logger;
32
39 public function __construct( array $params ) {
40 $this->params = $params;
41 if ( isset( $params['domain'] ) ) {
42 $this->dbDomain = $params['domain'];
43 $this->isDbDomainExplicit = empty( $params['isDomainImplicit'] );
44 } else {
45 throw new InvalidArgumentException( 'Missing DB "domain" parameter.' );
46 }
47
48 $this->logger = $params['logger'] ?? new NullLogger();
49 }
50
51 public function setLogger( LoggerInterface $logger ): void {
52 $this->logger = $logger;
53 }
54
62 abstract public function fetchFromURL( $url );
63
70 public function batchFetchFromURLs( array $urls ) {
71 $retval = [];
72 foreach ( $urls as $url ) {
73 $data = $this->fetchFromURL( $url );
74 // Dont return when false to allow for simpler implementations
75 if ( $data !== false ) {
76 $retval[$url] = $data;
77 }
78 }
79
80 return $retval;
81 }
82
91 abstract public function store( $location, $data );
92
100 public function isReadOnly( $location ) {
101 return false;
102 }
103}
Base class for external storage.
array $params
Usage context options for this instance.
setLogger(LoggerInterface $logger)
fetchFromURL( $url)
Fetch data from given external store URL.
bool $isDbDomainExplicit
Whether this was factoried with an explicit DB domain.
store( $location, $data)
Insert a data item into a given location.
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
isReadOnly( $location)
Check if a given location is read-only.
string $dbDomain
Default database domain to store content under.