Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
StreamNameMapper | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
resolve | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\EventBus; |
4 | |
5 | /** |
6 | * Maps from default names of streams to the actual stream name that will be |
7 | * produced. Unconfigured streams will produce to the default name. This allows |
8 | * wikis with special considerations, such as access restricted wikis in the |
9 | * same cluster as public wikis, to produce their events to a separate stream |
10 | * such that the public streams will not leak private details. Additionally |
11 | * this allows developers to vary the stream name used in testing and staging |
12 | * environments. |
13 | * This class is not generically applied to all events, rather HookHandlers |
14 | * should take this as a constructor argument and use the `resolve` method |
15 | * to determine what stream to send events to. |
16 | */ |
17 | class StreamNameMapper { |
18 | /** |
19 | * Key in MainConfig which will be used to map from EventBus owned 'stream names' |
20 | * to the concrete stream to emit events to. |
21 | * This config can be used to override the name of the stream that |
22 | * will be produced to. |
23 | */ |
24 | public const STREAM_NAMES_MAP_CONFIG_KEY = 'EventBusStreamNamesMap'; |
25 | |
26 | /** |
27 | * Map from the default stream name to it's alias. Unlisted streams will |
28 | * use the default stream name. |
29 | * @var array<string, string> |
30 | */ |
31 | private array $streamNamesMap; |
32 | |
33 | /** |
34 | * @param array<string, string> $streamNamesMap Map from the default stream |
35 | * name to it's alias. |
36 | */ |
37 | public function __construct( array $streamNamesMap ) { |
38 | $this->streamNamesMap = $streamNamesMap; |
39 | } |
40 | |
41 | /** |
42 | * @param string $name The default name of the stream |
43 | * @return string The stream to produce events to |
44 | */ |
45 | public function resolve( string $name ): string { |
46 | return $this->streamNamesMap[$name] ?? $name; |
47 | } |
48 | } |