42 $this->directory = $conf[
'directory'];
46 if ( !file_exists( $this->directory ) && !
wfMkdirParents( $this->directory,
null, __METHOD__ ) ) {
47 throw new MWException(
"Unable to create the localisation store " .
48 "directory \"{$this->directory}\"" );
51 $this->currentLang = $code;
52 $this->fname = $this->directory .
'/' . $code .
'.l10n.php';
53 $this->data[$code] = [];
54 if ( file_exists( $this->fname ) ) {
59 public function set( $key, $value ) {
70 foreach ( $arr as $key => $value ) {
71 if ( is_scalar( $value )
73 || ( is_array( $value ) && self::isValueArray( $value ) )
89 public static function encode( $value ) {
90 if ( is_array( $value ) && self::isValueArray( $value ) ) {
93 return [
'v', $value ];
95 if ( is_array( $value ) || is_object( $value ) ) {
101 if ( is_scalar( $value ) || $value ===
null ) {
106 throw new RuntimeException(
'Cannot encode ' . var_export( $value,
true ) );
116 public static function decode( $encoded ) {
117 if ( !is_array( $encoded ) ) {
132 return array_map( [ __CLASS__,
'decode' ],
$data );
134 throw new RuntimeException(
135 'Unable to decode ' . var_export( $encoded,
true ) );
141 $out = $writer->create(
142 $this->data[$this->currentLang],
143 'Generated by LCStoreStaticArray.php -- do not edit!'
145 file_put_contents( $this->fname, $out );
147 unset( $this->data[$this->currentLang] );
148 $this->currentLang =
null;
152 public function get( $code, $key ) {
153 if ( !array_key_exists( $code, $this->data ) ) {
154 $fname = $this->directory .
'/' . $code .
'.l10n.php';
155 if ( !file_exists(
$fname ) ) {
158 $this->data[$code] = require
$fname;
160 $data = $this->data[$code];
161 if ( array_key_exists( $key,
$data ) ) {
unserialize( $serialized)
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
finishWrite()
Finish a write transaction.
static encode( $value)
Encodes a value into an array format.
static decode( $encoded)
Decode something that was encoded with encode.
array $data
Localisation data.
startWrite( $code)
Start a write transaction.
string $directory
Directory for cache files.
string null $currentLang
Current language code.
static isValueArray(array $arr)
Determine whether this array contains only scalar values.
Interface for the persistence layer of LocalisationCache.