Page MenuHomeWickedGov Phorge

LazyLocalizationContext.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

LazyLocalizationContext.php

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Language;
/**
* Wrapper for injecting a LocalizationContext with lazy initialization.
*
* @since 1.42
* @ingroup Language
*/
class LazyLocalizationContext implements LocalizationContext {
/** @var callable */
private $instantiator;
private ?LocalizationContext $context = null;
/**
* @param callable $instantiator
*/
public function __construct( callable $instantiator ) {
$this->instantiator = $instantiator;
}
private function resolve(): LocalizationContext {
if ( !$this->context ) {
$this->context = ( $this->instantiator )();
}
return $this->context;
}
public function getLanguageCode() {
return $this->resolve()->getLanguageCode();
}
public function msg( $key, ...$params ) {
return $this->resolve()->msg( $key, ...$params );
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, May 16, 17:21 (9 h, 44 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8b/50/a4c19efe1755793fa68649f1a5c9
Default Alt Text
LazyLocalizationContext.php (1 KB)

Event Timeline