MediaWiki master
ExternalStoreMedium.php
Go to the documentation of this file.
1<?php
8
9use InvalidArgumentException;
10use Psr\Log\LoggerAwareInterface;
11use Psr\Log\LoggerInterface;
12use Psr\Log\NullLogger;
13
25abstract class ExternalStoreMedium implements LoggerAwareInterface {
27 protected $params = [];
29 protected $dbDomain;
32
34 protected $logger;
35
42 public function __construct( array $params ) {
43 $this->params = $params;
44 if ( isset( $params['domain'] ) ) {
45 $this->dbDomain = $params['domain'];
46 $this->isDbDomainExplicit = empty( $params['isDomainImplicit'] );
47 } else {
48 throw new InvalidArgumentException( 'Missing DB "domain" parameter.' );
49 }
50
51 $this->logger = $params['logger'] ?? new NullLogger();
52 }
53
54 public function setLogger( LoggerInterface $logger ): void {
55 $this->logger = $logger;
56 }
57
65 abstract public function fetchFromURL( $url );
66
73 public function batchFetchFromURLs( array $urls ) {
74 $retval = [];
75 foreach ( $urls as $url ) {
76 $data = $this->fetchFromURL( $url );
77 // Dont return when false to allow for simpler implementations
78 if ( $data !== false ) {
79 $retval[$url] = $data;
80 }
81 }
82
83 return $retval;
84 }
85
94 abstract public function store( $location, $data );
95
103 public function isReadOnly( $location ) {
104 return false;
105 }
106}
107
109class_alias( ExternalStoreMedium::class, 'ExternalStoreMedium' );
string $dbDomain
Default database domain to store content under.
store( $location, $data)
Insert a data item into a given location.
fetchFromURL( $url)
Fetch data from given external store URL.
array $params
Usage context options for this instance.
bool $isDbDomainExplicit
Whether this was factoried with an explicit DB domain.
isReadOnly( $location)
Check if a given location is read-only.
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.