Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Integration
0.00% covered (danger)
0.00%
0 / 5
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 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getContextAttribute
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\EventLogging\MetricsPlatform;
4
5use IContextSource;
6use Wikimedia\MetricsPlatform\Integration as MetricsPlatformIntegration;
7
8/**
9 * Provides the following functionality for the Metrics Platform Client:
10 *
11 * 1. Sending events to a remote service via EventBus; and
12 * 2. Gets the values of various context attributes from the execution environment
13 *
14 * Note well that #2 is done lazily, during the first call to `Integration#getContextAttribute()`
15 * and not at construction time, which keeps the cost of instantiating `Integration` instances low.
16 *
17 * @internal
18 */
19class Integration implements MetricsPlatformIntegration {
20
21    /**
22     * @var ContextAttributesFactory
23     */
24    private $contextAttributesFactory;
25
26    /**
27     * @var IContextSource
28     */
29    private $contextSource;
30
31    /**
32     * @var array
33     */
34    private $contextAttributes;
35
36    public function __construct(
37        ContextAttributesFactory $contextAttributesFactory,
38        IContextSource $contextSource
39    ) {
40        $this->contextAttributesFactory = $contextAttributesFactory;
41        $this->contextSource = $contextSource;
42    }
43
44    /** @inheritDoc */
45    public function getContextAttribute( string $name ) {
46        $contextAttributes =
47            $this->contextAttributes ??= $this->contextAttributesFactory->newContextAttributes( $this->contextSource );
48
49        return $contextAttributes[ $name ] ?? null;
50    }
51}