MediaWiki  master
NameTableStoreFactory.php
Go to the documentation of this file.
1 <?php
20 namespace MediaWiki\Storage;
21 
23 use WANObjectCache;
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 }
getSlotRoles( $wiki=false)
Get a NameTableStore for the slot_roles table.
getChangeTagDef( $wiki=false)
Get a NameTableStore for the change_tag_def table.
__construct(ILBFactory $lbFactory, WANObjectCache $cache, LoggerInterface $logger)
An interface for generating database load balancers.
Definition: ILBFactory.php:33
getContentModels( $wiki=false)
Get a NameTableStore for the content_models table.