Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
EchoEventDigestFormatter | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
msg | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
format | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
formatModels | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Formatters; |
4 | |
5 | use Language; |
6 | use MediaWiki\Extension\Notifications\Model\Event; |
7 | use MediaWiki\User\User; |
8 | use Message; |
9 | |
10 | /** |
11 | * Abstract class for formatters that process multiple events. |
12 | * |
13 | * The formatter does not maintain any state except for the |
14 | * arguments passed in the constructor (user and language) |
15 | */ |
16 | abstract class EchoEventDigestFormatter { |
17 | |
18 | /** @var User */ |
19 | protected $user; |
20 | |
21 | /** @var Language */ |
22 | protected $language; |
23 | |
24 | public function __construct( User $user, Language $language ) { |
25 | $this->user = $user; |
26 | $this->language = $language; |
27 | } |
28 | |
29 | /** |
30 | * Equivalent to IContextSource::msg for the current |
31 | * language |
32 | * |
33 | * @param string $key |
34 | * @param mixed ...$params |
35 | * @return Message |
36 | */ |
37 | protected function msg( string $key, ...$params ) { |
38 | $msg = wfMessage( $key, ...$params ); |
39 | $msg->inLanguage( $this->language ); |
40 | |
41 | return $msg; |
42 | } |
43 | |
44 | /** |
45 | * @param Event[] $events |
46 | * @param string $distributionType 'web' or 'email' |
47 | * @return string[]|false Output format depends on implementation, false if it cannot be formatted |
48 | */ |
49 | final public function format( array $events, $distributionType ) { |
50 | $models = []; |
51 | foreach ( $events as $event ) { |
52 | $model = EchoEventPresentationModel::factory( $event, $this->language, $this->user, $distributionType ); |
53 | if ( $model->canRender() ) { |
54 | $models[] = $model; |
55 | } |
56 | } |
57 | |
58 | return $models ? $this->formatModels( $models ) : false; |
59 | } |
60 | |
61 | /** |
62 | * @param EchoEventPresentationModel[] $models |
63 | * @return string[]|string |
64 | */ |
65 | abstract protected function formatModels( array $models ); |
66 | } |