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