Debian Codegraph @

includes/poolcounter/PoolCounterFactory.php

raw symbols SCIP
1 <?php
2 namespace MediaWiki\PoolCounter;
3
4 use Psr\Log\LoggerInterface;
5
6 /**
7 * @since 1.40
8 */
9 class PoolCounterFactory {
10 private ?PoolCounterConnectionManager $manager = null;
11 private ?array $typeConfigs;
12 private array $clientConf;
13 private LoggerInterface $logger;
14
15 /**
16 * @internal For use by ServiceWiring
17 * @param array|null $typeConfigs See $wgPoolCounterConf
18 * @param array $clientConf See $wgPoolCountClientConf
19 * @param LoggerInterface $logger
20 */
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
32 /**
33 * Get a PoolCounter.
34 *
35 * @internal This should only be called from PoolCounterWork
36 * @param string $type The class of actions to limit concurrency for (task type)
37 * @param string $key
38 * @return PoolCounter
39 */
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 }
52 /** @var PoolCounter $poolCounter */
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 }