MediaWiki  1.28.1
ReplicatedBagOStuff.php
Go to the documentation of this file.
1 <?php
36  protected $writeStore;
38  protected $readStore;
39 
50  public function __construct( $params ) {
51  parent::__construct( $params );
52 
53  if ( !isset( $params['writeFactory'] ) ) {
54  throw new InvalidArgumentException(
55  __METHOD__ . ': the "writeFactory" parameter is required' );
56  }
57  if ( !isset( $params['readFactory'] ) ) {
58  throw new InvalidArgumentException(
59  __METHOD__ . ': the "readFactory" parameter is required' );
60  }
61 
62  $opts = [ 'reportDupes' => false ]; // redundant
63  $this->writeStore = ( $params['writeFactory'] instanceof BagOStuff )
64  ? $params['writeFactory']
65  : ObjectFactory::getObjectFromSpec( $opts + $params['writeFactory'] );
66  $this->readStore = ( $params['readFactory'] instanceof BagOStuff )
67  ? $params['readFactory']
68  : ObjectFactory::getObjectFromSpec( $opts + $params['readFactory'] );
69  $this->attrMap = $this->mergeFlagMaps( [ $this->readStore, $this->writeStore ] );
70  }
71 
72  public function setDebug( $debug ) {
73  $this->writeStore->setDebug( $debug );
74  $this->readStore->setDebug( $debug );
75  }
76 
77  protected function doGet( $key, $flags = 0 ) {
78  return ( $flags & self::READ_LATEST )
79  ? $this->writeStore->get( $key, $flags )
80  : $this->readStore->get( $key, $flags );
81  }
82 
83  public function getMulti( array $keys, $flags = 0 ) {
84  return ( $flags & self::READ_LATEST )
85  ? $this->writeStore->getMulti( $keys, $flags )
86  : $this->readStore->getMulti( $keys, $flags );
87  }
88 
89  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
90  return $this->writeStore->set( $key, $value, $exptime, $flags );
91  }
92 
93  public function delete( $key ) {
94  return $this->writeStore->delete( $key );
95  }
96 
97  public function add( $key, $value, $exptime = 0 ) {
98  return $this->writeStore->add( $key, $value, $exptime );
99  }
100 
101  public function incr( $key, $value = 1 ) {
102  return $this->writeStore->incr( $key, $value );
103  }
104 
105  public function decr( $key, $value = 1 ) {
106  return $this->writeStore->decr( $key, $value );
107  }
108 
109  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
110  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
111  }
112 
113  public function unlock( $key ) {
114  return $this->writeStore->unlock( $key );
115  }
116 
117  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
118  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
119  }
120 
121  public function getLastError() {
122  return ( $this->writeStore->getLastError() != self::ERR_NONE )
123  ? $this->writeStore->getLastError()
124  : $this->readStore->getLastError();
125  }
126 
127  public function clearLastError() {
128  $this->writeStore->clearLastError();
129  $this->readStore->clearLastError();
130  }
131 }
__construct($params)
Constructor.
the array() calling protocol came about after MediaWiki 1.4rc1.
static getObjectFromSpec($spec)
Instantiate an object based on a specification array.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$value
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
getMulti(array $keys, $flags=0)
$params
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map...
Definition: BagOStuff.php:783
add($key, $value, $exptime=0)
lock($key, $timeout=6, $expiry=6, $rclass= '')
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
set($key, $value, $exptime=0, $flags=0)
merge($key, callable $callback, $exptime=0, $attempts=10, $flags=0)
$debug
Definition: mcc.php:31
A cache class that directs writes to one set of servers and reads to another.