MediaWiki  1.30.0
ForeignDBRepo.php
Go to the documentation of this file.
1 <?php
26 
32 class ForeignDBRepo extends LocalRepo {
34  protected $dbType;
35 
37  protected $dbServer;
38 
40  protected $dbUser;
41 
43  protected $dbPassword;
44 
46  protected $dbName;
47 
49  protected $dbFlags;
50 
52  protected $tablePrefix;
53 
55  protected $hasSharedCache;
56 
58  protected $dbConn;
59 
61  protected $fileFactory = [ 'ForeignDBFile', 'newFromTitle' ];
63  protected $fileFromRowFactory = [ 'ForeignDBFile', 'newFromRow' ];
64 
68  function __construct( $info ) {
69  parent::__construct( $info );
70  $this->dbType = $info['dbType'];
71  $this->dbServer = $info['dbServer'];
72  $this->dbUser = $info['dbUser'];
73  $this->dbPassword = $info['dbPassword'];
74  $this->dbName = $info['dbName'];
75  $this->dbFlags = $info['dbFlags'];
76  $this->tablePrefix = $info['tablePrefix'];
77  $this->hasSharedCache = $info['hasSharedCache'];
78  }
79 
83  function getMasterDB() {
84  if ( !isset( $this->dbConn ) ) {
85  $func = $this->getDBFactory();
86  $this->dbConn = $func( DB_MASTER );
87  }
88 
89  return $this->dbConn;
90  }
91 
95  function getReplicaDB() {
96  return $this->getMasterDB();
97  }
98 
102  protected function getDBFactory() {
104  $params = [
105  'host' => $this->dbServer,
106  'user' => $this->dbUser,
107  'password' => $this->dbPassword,
108  'dbname' => $this->dbName,
109  'flags' => $this->dbFlags,
110  'tablePrefix' => $this->tablePrefix,
111  'foreign' => true,
112  ];
113 
114  return function ( $index ) use ( $type, $params ) {
115  return Database::factory( $type, $params );
116  };
117  }
118 
122  function hasSharedCache() {
123  return $this->hasSharedCache;
124  }
125 
132  function getSharedCacheKey( /*...*/ ) {
133  if ( $this->hasSharedCache() ) {
134  $args = func_get_args();
135  array_unshift( $args, $this->dbName, $this->tablePrefix );
136 
137  return call_user_func_array( 'wfForeignMemcKey', $args );
138  } else {
139  return false;
140  }
141  }
142 
143  protected function assertWritableRepo() {
144  throw new MWException( static::class . ': write operations are not supported.' );
145  }
146 
153  function getInfo() {
154  return FileRepo::getInfo();
155  }
156 }
ForeignDBRepo\$dbUser
string $dbUser
Definition: ForeignDBRepo.php:40
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:45
ForeignDBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBRepo.php:102
ForeignDBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBRepo.php:153
ForeignDBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBRepo.php:55
ForeignDBRepo\$dbName
string $dbName
Definition: ForeignDBRepo.php:46
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1896
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ForeignDBRepo\getReplicaDB
getReplicaDB()
Definition: ForeignDBRepo.php:95
$params
$params
Definition: styleTest.css.php:40
ForeignDBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBRepo.php:143
ForeignDBRepo\$fileFactory
callable $fileFactory
Definition: ForeignDBRepo.php:61
php
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
ForeignDBRepo\$dbServer
string $dbServer
Definition: ForeignDBRepo.php:37
ForeignDBRepo\$dbConn
IDatabase $dbConn
Definition: ForeignDBRepo.php:58
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignDBRepo\$dbPassword
string $dbPassword
Definition: ForeignDBRepo.php:43
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ForeignDBRepo\$tablePrefix
string $tablePrefix
Definition: ForeignDBRepo.php:52
ForeignDBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBRepo.php:122
ForeignDBRepo
A foreign repository with an accessible MediaWiki database.
Definition: ForeignDBRepo.php:32
ForeignDBRepo\getMasterDB
getMasterDB()
Definition: ForeignDBRepo.php:83
ForeignDBRepo\getSharedCacheKey
getSharedCacheKey()
Get a key on the primary cache for this repository.
Definition: ForeignDBRepo.php:132
$args
if( $line===false) $args
Definition: cdb.php:63
ForeignDBRepo\$dbType
string $dbType
Definition: ForeignDBRepo.php:34
ForeignDBRepo\$dbFlags
string $dbFlags
Definition: ForeignDBRepo.php:49
ForeignDBRepo\__construct
__construct( $info)
Definition: ForeignDBRepo.php:68
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ForeignDBRepo\$fileFromRowFactory
callable $fileFromRowFactory
Definition: ForeignDBRepo.php:63
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:35
$type
$type
Definition: testCompression.php:48