Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MetricsClientFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
newMetricsClient | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\EventLogging\MetricsPlatform; |
4 | |
5 | use IContextSource; |
6 | use MediaWiki\Extension\EventLogging\EventSubmitter\EventSubmitter; |
7 | use MediaWiki\Extension\EventLogging\MetricsPlatform\EventSubmitter as MetricsPlatformEventSubmitter; |
8 | use Psr\Log\LoggerInterface; |
9 | use Wikimedia\MetricsPlatform\MetricsClient; |
10 | use Wikimedia\MetricsPlatform\StreamConfig\StreamConfigFactory; |
11 | |
12 | class MetricsClientFactory { |
13 | |
14 | /** @var ContextAttributesFactory */ |
15 | private $contextAttributesFactory; |
16 | |
17 | /** @var EventSubmitter */ |
18 | private $eventSubmitter; |
19 | |
20 | /** @var array|bool */ |
21 | private $streamConfigs; |
22 | |
23 | /** @var LoggerInterface */ |
24 | private $logger; |
25 | |
26 | public function __construct( |
27 | ContextAttributesFactory $contextAttributesFactory, |
28 | EventSubmitter $eventSubmitter, |
29 | $streamConfigs, |
30 | LoggerInterface $logger |
31 | ) { |
32 | $this->contextAttributesFactory = $contextAttributesFactory; |
33 | $this->eventSubmitter = $eventSubmitter; |
34 | $this->streamConfigs = $streamConfigs; |
35 | $this->logger = $logger; |
36 | } |
37 | |
38 | public function newMetricsClient( IContextSource $requestContext ): MetricsClient { |
39 | $eventSubmitter = new MetricsPlatformEventSubmitter( $this->eventSubmitter ); |
40 | $integration = new Integration( $this->contextAttributesFactory, $requestContext ); |
41 | |
42 | // TODO: EventStreamConfig (and EventLogging to some extent) and the PHP Metrics Platform |
43 | // Client have representations of stream configs. Extract a single representation into a |
44 | // library. |
45 | $streamConfigs = new StreamConfigFactory( $this->streamConfigs ); |
46 | |
47 | return new MetricsClient( $eventSubmitter, $integration, $streamConfigs, $this->logger ); |
48 | } |
49 | } |