Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LazyLocalizationContext | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| resolve | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getLanguageCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| msg | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Language; |
| 8 | |
| 9 | /** |
| 10 | * Wrapper for injecting a LocalizationContext with lazy initialization. |
| 11 | * |
| 12 | * @since 1.42 |
| 13 | * @ingroup Language |
| 14 | */ |
| 15 | class LazyLocalizationContext implements LocalizationContext { |
| 16 | |
| 17 | /** @var callable */ |
| 18 | private $instantiator; |
| 19 | |
| 20 | private ?LocalizationContext $context = null; |
| 21 | |
| 22 | public function __construct( callable $instantiator ) { |
| 23 | $this->instantiator = $instantiator; |
| 24 | } |
| 25 | |
| 26 | private function resolve(): LocalizationContext { |
| 27 | if ( !$this->context ) { |
| 28 | $this->context = ( $this->instantiator )(); |
| 29 | } |
| 30 | |
| 31 | return $this->context; |
| 32 | } |
| 33 | |
| 34 | /** @inheritDoc */ |
| 35 | public function getLanguageCode() { |
| 36 | return $this->resolve()->getLanguageCode(); |
| 37 | } |
| 38 | |
| 39 | /** @inheritDoc */ |
| 40 | public function msg( $key, ...$params ) { |
| 41 | return $this->resolve()->msg( $key, ...$params ); |
| 42 | } |
| 43 | } |