MediaWiki  master
PoolCounterFactory.php
Go to the documentation of this file.
1 <?php
2 namespace MediaWiki\PoolCounter;
3 
4 use PoolCounter;
6 
11  private ?PoolCounterConnectionManager $manager = null;
12  private ?array $typeConfigs;
13  private array $clientConf;
14 
20  public function __construct( ?array $typeConfigs, array $clientConf ) {
21  $this->typeConfigs = $typeConfigs;
22  $this->clientConf = $clientConf;
23  }
24 
25  private function getClientManager(): PoolCounterConnectionManager {
26  $this->manager ??= new PoolCounterConnectionManager( $this->clientConf );
27  return $this->manager;
28  }
29 
38  public function create( string $type, string $key ): PoolCounter {
39  $conf = $this->typeConfigs[$type] ?? null;
40  if ( $conf === null ) {
41  return new PoolCounterNull();
42  }
43 
44  $class = $conf['class'] ?? null;
45  if ( $class === 'PoolCounter_Client' ) {
46  // Since 1.16: Introduce PoolCounter_Client in PoolCounter extension.
47  // Since 1.40: Move to core as symbolic name, discourage use of class name.
48  $class = PoolCounterClient::class;
49  }
51  $poolCounter = new $class( $conf, $type, $key );
52 
53  // Support subclass for back-compat with the extension
54  if ( $poolCounter instanceof PoolCounterClient ) {
55  $poolCounter->setManager( $this->getClientManager() );
56  }
57 
58  return $poolCounter;
59  }
60 }
Helper for \MediaWiki\PoolCounter\PoolCounterClient.
create(string $type, string $key)
Get a PoolCounter.
__construct(?array $typeConfigs, array $clientConf)
A default PoolCounter, which provides no locking.
Semaphore semantics to restrict how many workers may concurrently perform a task.
Definition: PoolCounter.php:51