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