MediaWiki  1.27.2
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  $this->writeStore = ( $params['writeFactory'] instanceof BagOStuff )
63  ? $params['writeFactory']
64  : ObjectFactory::getObjectFromSpec( $params['writeFactory'] );
65  $this->readStore = ( $params['readFactory'] instanceof BagOStuff )
66  ? $params['readFactory']
67  : ObjectFactory::getObjectFromSpec( $params['readFactory'] );
68  }
69 
70  public function setDebug( $debug ) {
71  $this->writeStore->setDebug( $debug );
72  $this->readStore->setDebug( $debug );
73  }
74 
75  protected function doGet( $key, $flags = 0 ) {
76  return ( $flags & self::READ_LATEST )
77  ? $this->writeStore->get( $key, $flags )
78  : $this->readStore->get( $key, $flags );
79  }
80 
81  public function getMulti( array $keys, $flags = 0 ) {
82  return ( $flags & self::READ_LATEST )
83  ? $this->writeStore->getMulti( $keys, $flags )
84  : $this->readStore->getMulti( $keys, $flags );
85  }
86 
87  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
88  return $this->writeStore->set( $key, $value, $exptime, $flags );
89  }
90 
91  public function delete( $key ) {
92  return $this->writeStore->delete( $key );
93  }
94 
95  public function add( $key, $value, $exptime = 0 ) {
96  return $this->writeStore->add( $key, $value, $exptime );
97  }
98 
99  public function incr( $key, $value = 1 ) {
100  return $this->writeStore->incr( $key, $value );
101  }
102 
103  public function decr( $key, $value = 1 ) {
104  return $this->writeStore->decr( $key, $value );
105  }
106 
107  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
108  return $this->writeStore->lock( $key, $timeout, $expiry, $rclass );
109  }
110 
111  public function unlock( $key ) {
112  return $this->writeStore->unlock( $key );
113  }
114 
115  public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
116  return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags );
117  }
118 
119  public function getLastError() {
120  return ( $this->writeStore->getLastError() != self::ERR_NONE )
121  ? $this->writeStore->getLastError()
122  : $this->readStore->getLastError();
123  }
124 
125  public function clearLastError() {
126  $this->writeStore->clearLastError();
127  $this->readStore->clearLastError();
128  }
129 }
__construct($params)
Constructor.
the array() calling protocol came about after MediaWiki 1.4rc1.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
static getObjectFromSpec($spec)
Instantiate an object based on a specification array.
$value
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
getMulti(array $keys, $flags=0)
merge($key, $callback, $exptime=0, $attempts=10, $flags=0)
$params
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)
$debug
Definition: mcc.php:31
A cache class that directs writes to one set of servers and reads to another.