]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Add closing PHP tags to JSON config files 570/head
authorArthurHoaro <arthur@hoa.ro>
Mon, 20 Jun 2016 16:30:37 +0000 (18:30 +0200)
committerArthurHoaro <arthur@hoa.ro>
Mon, 20 Jun 2016 16:30:37 +0000 (18:30 +0200)
application/config/ConfigJson.php
tests/config/ConfigJsonTest.php
tests/utils/config/configInvalid.json.php
tests/utils/config/configJson.json.php

index 94693c860c5f89a1e72fb0bc79d43d70b906cd4b..d07fefee5c2968292eba37c240861d8eb2bf43dc 100644 (file)
@@ -17,6 +17,7 @@ class ConfigJson implements ConfigIO
         }
         $data = file_get_contents($filepath);
         $data = str_replace(self::getPhpHeaders(), '', $data);
+        $data = str_replace(self::getPhpSuffix(), '', $data);
         $data = json_decode($data, true);
         if ($data === null) {
             $error = json_last_error();
@@ -32,7 +33,7 @@ class ConfigJson implements ConfigIO
     {
         // JSON_PRETTY_PRINT is available from PHP 5.4.
         $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
-        $data = self::getPhpHeaders() . json_encode($conf, $print);
+        $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
         if (!file_put_contents($filepath, $data)) {
             throw new IOException(
                 $filepath,
@@ -62,4 +63,16 @@ class ConfigJson implements ConfigIO
     {
         return '<?php /*'. PHP_EOL;
     }
+
+    /**
+     * Get PHP comment closing tags.
+     *
+     * Static method for consistency with getPhpHeaders.
+     *
+     * @return string PHP comment closing.
+     */
+    public static function getPhpSuffix()
+    {
+        return PHP_EOL . '*/ ?>';
+    }
 }
index 359e9112593b8351980c537850bab92a9aff3562..99c88820ca43abb66920d19fef1617d7d18e377a 100644 (file)
@@ -88,7 +88,7 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
         } else {
             $expected = '{"credentials":{"login":"root"},"resource":{"datastore":"data\/datastore.php"},"redirector":{"url":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}';
         }
-        $expected = ConfigJson::getPhpHeaders() . $expected;
+        $expected = ConfigJson::getPhpHeaders() . $expected . ConfigJson::getPhpSuffix();
         $this->assertEquals($expected, file_get_contents($dataFile));
         unlink($dataFile);
     }
index c53e471deb63050b202b330b95a474695065af4c..167f2168eb134f7e6de62572ee706f7ab21c197d 100644 (file)
@@ -2,3 +2,4 @@
 {
     bad: bad,
 }
+*/ ?>
\ No newline at end of file
index c54882c3dad8bbb7fb09e300b09fd48a98150492..06a302e875b8e61779a0981c85731c63ebb18723 100644 (file)
@@ -30,3 +30,5 @@
         "WALLABAG_VERSION": 1
     }
 }
+*/ ?>
+