Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PoolCounterFactory | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getClientManager | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
create | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | namespace MediaWiki\PoolCounter; |
3 | |
4 | use Psr\Log\LoggerInterface; |
5 | use Wikimedia\Telemetry\TracerInterface; |
6 | |
7 | /** |
8 | * @since 1.40 |
9 | */ |
10 | class PoolCounterFactory { |
11 | private ?PoolCounterConnectionManager $manager = null; |
12 | private ?array $typeConfigs; |
13 | private array $clientConf; |
14 | private LoggerInterface $logger; |
15 | private TracerInterface $tracer; |
16 | |
17 | /** |
18 | * @internal For use by ServiceWiring |
19 | * @param array|null $typeConfigs See $wgPoolCounterConf |
20 | * @param array $clientConf See $wgPoolCountClientConf |
21 | * @param LoggerInterface $logger |
22 | */ |
23 | public function __construct( ?array $typeConfigs, array $clientConf, |
24 | LoggerInterface $logger, TracerInterface $tracer ) { |
25 | $this->typeConfigs = $typeConfigs; |
26 | $this->clientConf = $clientConf; |
27 | $this->logger = $logger; |
28 | $this->tracer = $tracer; |
29 | } |
30 | |
31 | private function getClientManager(): PoolCounterConnectionManager { |
32 | $this->manager ??= new PoolCounterConnectionManager( $this->clientConf ); |
33 | return $this->manager; |
34 | } |
35 | |
36 | /** |
37 | * Get a PoolCounter. |
38 | * |
39 | * @internal This should only be called from PoolCounterWork |
40 | * @param string $type The class of actions to limit concurrency for (task type) |
41 | * @param string $key |
42 | * @return PoolCounter |
43 | */ |
44 | public function create( string $type, string $key ): PoolCounter { |
45 | $conf = $this->typeConfigs[$type] ?? null; |
46 | if ( $conf === null ) { |
47 | return new PoolCounterNull(); |
48 | } |
49 | |
50 | $class = $conf['class'] ?? null; |
51 | if ( $class === 'PoolCounter_Client' ) { |
52 | // Since 1.16: Introduce PoolCounter_Client in PoolCounter extension. |
53 | // Since 1.40: Move to core as symbolic name, discourage use of class name. |
54 | $class = PoolCounterClient::class; |
55 | } |
56 | /** @var PoolCounter $poolCounter */ |
57 | $poolCounter = new $class( $conf, $type, $key ); |
58 | $poolCounter->setLogger( $this->logger ); |
59 | $poolCounter->setTracer( $this->tracer ); |
60 | |
61 | // Support subclass for back-compat with the extension |
62 | if ( $poolCounter instanceof PoolCounterClient ) { |
63 | $poolCounter->setManager( $this->getClientManager() ); |
64 | } |
65 | |
66 | return $poolCounter; |
67 | } |
68 | } |