From e4676f42ffceae5249c4d3f02f1d43c2f2ef44e5 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 19 Aug 2018 03:17:52 -0700 Subject: [PATCH] Use StaticArrayWriter in LCStoreStaticArray ...instead of var_export(), which uses array() syntax and spaces for indentation. Also get rid of some unnecessary closure indirection. Bug: T200626 Change-Id: I5db8ade50fcba5ecf394817b2d14295620314ea7 --- .../cache/localisation/LCStoreStaticArray.php | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/includes/cache/localisation/LCStoreStaticArray.php b/includes/cache/localisation/LCStoreStaticArray.php index 38700b85b5..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 */ @@ -84,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 ) ); @@ -109,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 ) ); @@ -119,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; } -- 2.20.1