X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fcache%2Flocalisation%2FLCStoreStaticArray.php;h=3b6da7394453bc23d242961205284d11e28df8b3;hb=e4676f42ffceae5249c4d3f02f1d43c2f2ef44e5;hp=602c0ac463e1297e97257b7dac9d051bb7d8d70d;hpb=3d95da4952619f9f773298c4461ccfc646fb18a9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/cache/localisation/LCStoreStaticArray.php b/includes/cache/localisation/LCStoreStaticArray.php index 602c0ac463..3b6da73944 100644 --- a/includes/cache/localisation/LCStoreStaticArray.php +++ b/includes/cache/localisation/LCStoreStaticArray.php @@ -20,6 +20,8 @@ * @file */ +use Wikimedia\StaticArrayWriter; + /** * @since 1.26 */ @@ -47,6 +49,13 @@ class LCStoreStaticArray implements LCStore { } public function startWrite( $code ) { + if ( !file_exists( $this->directory ) ) { + if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) { + throw new MWException( "Unable to create the localisation store " . + "directory \"{$this->directory}\"" ); + } + } + $this->currentLang = $code; $this->fname = $this->directory . '/' . $code . '.l10n.php'; $this->data[$code] = []; @@ -77,9 +86,7 @@ class LCStoreStaticArray implements LCStore { } if ( is_array( $value ) ) { // [A]rray - return [ 'a', array_map( function ( $v ) { - return LCStoreStaticArray::encode( $v ); - }, $value ) ]; + return [ 'a', array_map( 'LCStoreStaticArray::encode', $value ) ]; } throw new RuntimeException( 'Cannot encode ' . var_export( $value, true ) ); @@ -102,9 +109,7 @@ class LCStoreStaticArray implements LCStore { case 's': return unserialize( $data ); case 'a': - return array_map( function ( $v ) { - return LCStoreStaticArray::decode( $v ); - }, $data ); + return array_map( 'LCStoreStaticArray::decode', $data ); default: throw new RuntimeException( 'Unable to decode ' . var_export( $encoded, true ) ); @@ -112,13 +117,12 @@ class LCStoreStaticArray implements LCStore { } public function finishWrite() { - file_put_contents( - $this->fname, - "data[$this->currentLang], true ) . ';' + $writer = new StaticArrayWriter(); + $out = $writer->create( + $this->data[$this->currentLang], + 'Generated by LCStoreStaticArray.php -- do not edit!' ); + file_put_contents( $this->fname, $out ); $this->currentLang = null; $this->fname = null; }