23use InvalidArgumentException;
44 private $siteLangCode;
47 private $localisationCache;
50 private $langNameUtils;
53 private $fallbackCache = [];
68 $this->siteLangCode = $siteLangCode;
69 $this->localisationCache = $localisationCache;
70 $this->langNameUtils = $langNameUtils;
81 return $this->
getAll( $code )[0] ??
null;
93 public function getAll( $code, $mode = self::MESSAGES ) {
97 if ( $code ===
'en' || !$this->langNameUtils->isValidBuiltInCode( $code ) ) {
104 $ret = $this->localisationCache->getItem( $code,
'fallbackSequence' ) ?: [
'en' ];
111 $ret = $this->localisationCache->getItem( $code,
'originalFallbackSequence' );
115 throw new InvalidArgumentException(
"Invalid fallback mode \"$mode\"" );
131 $cacheKey =
"{$code}-{$this->siteLangCode}";
133 if ( !array_key_exists( $cacheKey, $this->fallbackCache ) ) {
134 $fallbacks = $this->
getAll( $code );
136 if ( $code === $this->siteLangCode ) {
138 $siteFallbacks = [ $code ];
141 $siteFallbacks = $this->
getAll( $this->siteLangCode );
142 array_unshift( $siteFallbacks, $this->siteLangCode );
145 $siteFallbacks = array_diff( $siteFallbacks, $fallbacks );
148 $this->fallbackCache[$cacheKey] = [ $fallbacks, $siteFallbacks ];
150 return $this->fallbackCache[$cacheKey];
Caching for the contents of localisation files.