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 public static function encode( $value ) {
71 if ( is_array( $value ) ) {
73 return [
'a', array_map(
'LCStoreStaticArray::encode', $value ) ];
75 if ( is_object( $value ) ) {
79 if ( is_scalar( $value ) || $value ===
null ) {
84 throw new RuntimeException(
'Cannot encode ' . var_export( $value,
true ) );
94 public static function decode( $encoded ) {
95 if ( !is_array( $encoded ) ) {
104 return array_map(
'LCStoreStaticArray::decode',
$data );
112 throw new RuntimeException(
113 'Unable to decode ' . var_export( $encoded,
true ) );
119 $out = $writer->create(
120 $this->data[$this->currentLang],
121 'Generated by LCStoreStaticArray.php -- do not edit!'
123 file_put_contents( $this->fname, $out );
125 unset( $this->data[$this->currentLang] );
126 $this->currentLang =
null;
130 public function get( $code, $key ) {
131 if ( !array_key_exists( $code, $this->data ) ) {
132 $fname = $this->directory .
'/' . $code .
'.l10n.php';
133 if ( !file_exists(
$fname ) ) {
136 $this->data[$code] = require
$fname;
138 $data = $this->data[$code];
139 if ( array_key_exists( $key,
$data ) ) {