diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-03-26 19:40:49 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-03-26 19:40:49 +0200 |
commit | ffc7417da6d81708a5b2c7f98d873879b292a7fc (patch) | |
tree | 76caf50bb2f368a5df5bf9780be529c6a7563abd | |
parent | dbc02ddf5e66c4f7439c6997ed1e6b59bfd98173 (diff) |
s/renderer: Extract json reformater method
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/service/renderer.php | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/application/service/renderer.php b/application/service/renderer.php index 66b6779a2..5da4cbd0a 100644 --- a/application/service/renderer.php +++ b/application/service/renderer.php @@ -34,22 +34,7 @@ class renderer { $content = file_get_contents($file); $linecount = count(explode("\n", $content)); - if ($lexer === "json" && $linecount === 1) { - $decoded_json = json_decode($content); - if ($decoded_json !== null && $decoded_json !== false) { - $pretty_json = json_encode($decoded_json, JSON_PRETTY_PRINT); - if ($pretty_json !== false) { - $content = $pretty_json; - $this->output_cache->render_now( - array( - "error_type" => "alert-info", - "error_message" => "<p>The file below has been reformated for readability. It may differ from the original.</p>" - ), - "file/fragments/alert-wide" - ); - } - } - } + $content = $this->reformat_json($lexer, $linecount, $content); if ($lexer == "ascii") { // TODO: use exec safe and catch exception @@ -165,5 +150,32 @@ class renderer { $this->output_cache->render_now($data, 'file/html_paste_footer'); } + /** + * @param $lexer + * @param $linecount + * @param $content + * @return string + */ + private function reformat_json($lexer, $linecount, $content) + { + if ($lexer === "json" && $linecount === 1) { + $decoded_json = json_decode($content); + if ($decoded_json !== null && $decoded_json !== false) { + $pretty_json = json_encode($decoded_json, JSON_PRETTY_PRINT); + if ($pretty_json !== false) { + $content = $pretty_json; + $this->output_cache->render_now( + array( + "error_type" => "alert-info", + "error_message" => "<p>The file below has been reformated for readability. It may differ from the original.</p>" + ), + "file/fragments/alert-wide" + ); + } + } + } + return $content; + } + } |