MediaWiki  1.32.0
NameTableStoreFactory.php
Go to the documentation of this file.
1 <?php
20 namespace MediaWiki\Storage;
21 
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 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Storage\NameTableStoreFactory\$info
static $info
Definition: NameTableStoreFactory.php:27
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
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
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
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
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:118
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:35
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