MediaWiki  1.34.0
NameTableStoreFactory.php
Go to the documentation of this file.
1 <?php
20 namespace MediaWiki\Storage;
21 
23 use WANObjectCache;
24 use Psr\Log\LoggerInterface;
25 
27  private static $info;
28  private $stores = [];
29 
31  private $lbFactory;
32 
34  private $cache;
35 
37  private $logger;
38 
39  private static function getTableInfo() {
40  if ( self::$info ) {
41  return self::$info;
42  }
43  self::$info = [
44  'change_tag_def' => [
45  'idField' => 'ctd_id',
46  'nameField' => 'ctd_name',
47  'normalizationCallback' => null,
48  'insertCallback' => function ( $insertFields ) {
49  $insertFields['ctd_user_defined'] = 0;
50  $insertFields['ctd_count'] = 0;
51  return $insertFields;
52  }
53  ],
54 
55  'content_models' => [
56  'idField' => 'model_id',
57  'nameField' => 'model_name',
64  ],
65 
66  'slot_roles' => [
67  'idField' => 'role_id',
68  'nameField' => 'role_name',
69  'normalizationCallback' => 'strtolower',
70  ],
71  ];
72  return self::$info;
73  }
74 
75  public function __construct(
78  LoggerInterface $logger
79  ) {
80  $this->lbFactory = $lbFactory;
81  $this->cache = $cache;
82  $this->logger = $logger;
83  }
84 
92  public function get( $tableName, $wiki = false ) : NameTableStore {
93  $infos = self::getTableInfo();
94  if ( !isset( $infos[$tableName] ) ) {
95  throw new \InvalidArgumentException( "Invalid table name \$tableName" );
96  }
97  if ( $wiki === $this->lbFactory->getLocalDomainID() ) {
98  $wiki = false;
99  }
100 
101  if ( isset( $this->stores[$tableName][$wiki] ) ) {
102  return $this->stores[$tableName][$wiki];
103  }
104 
105  $info = $infos[$tableName];
106  $store = new NameTableStore(
107  $this->lbFactory->getMainLB( $wiki ),
108  $this->cache,
110  $tableName,
111  $info['idField'],
112  $info['nameField'],
113  $info['normalizationCallback'] ?? null,
114  $wiki,
115  $info['insertCallback'] ?? null
116  );
117  $this->stores[$tableName][$wiki] = $store;
118  return $store;
119  }
120 
127  public function getChangeTagDef( $wiki = false ) : NameTableStore {
128  return $this->get( 'change_tag_def', $wiki );
129  }
130 
137  public function getContentModels( $wiki = false ) : NameTableStore {
138  return $this->get( 'content_models', $wiki );
139  }
140 
147  public function getSlotRoles( $wiki = false ) : NameTableStore {
148  return $this->get( 'slot_roles', $wiki );
149  }
150 }
MediaWiki\Storage\NameTableStoreFactory\$info
static $info
Definition: NameTableStoreFactory.php:27
MediaWiki\Storage\NameTableStoreFactory\getSlotRoles
getSlotRoles( $wiki=false)
Get a NameTableStore for the slot_roles table.
Definition: NameTableStoreFactory.php:147
MediaWiki\Storage\NameTableStoreFactory\$lbFactory
ILBFactory $lbFactory
Definition: NameTableStoreFactory.php:31
MediaWiki\Storage\NameTableStoreFactory\$cache
WANObjectCache $cache
Definition: NameTableStoreFactory.php:34
MediaWiki\Storage\NameTableStoreFactory\__construct
__construct(ILBFactory $lbFactory, WANObjectCache $cache, LoggerInterface $logger)
Definition: NameTableStoreFactory.php:75
MediaWiki\Storage\NameTableStoreFactory\getTableInfo
static getTableInfo()
Definition: NameTableStoreFactory.php:39
MediaWiki\Storage\NameTableStoreFactory\getContentModels
getContentModels( $wiki=false)
Get a NameTableStore for the content_models table.
Definition: NameTableStoreFactory.php:137
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:116
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:36
MediaWiki\Storage
Definition: BlobAccessException.php:23
MediaWiki\Storage\NameTableStoreFactory\getChangeTagDef
getChangeTagDef( $wiki=false)
Get a NameTableStore for the change_tag_def table.
Definition: NameTableStoreFactory.php:127
MediaWiki\Storage\NameTableStoreFactory\$logger
LoggerInterface $logger
Definition: NameTableStoreFactory.php:37
MediaWiki\Storage\NameTableStoreFactory
Definition: NameTableStoreFactory.php:26
MediaWiki\Storage\NameTableStoreFactory\$stores
$stores
Definition: NameTableStoreFactory.php:28
Wikimedia\Rdbms\ILBFactory
An interface for generating database load balancers.
Definition: ILBFactory.php:33