diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-03-26 19:30:11 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-03-26 19:30:49 +0200 |
commit | dbc02ddf5e66c4f7439c6997ed1e6b59bfd98173 (patch) | |
tree | da5e155ca889f8c2901a03e28069abcef865abe9 | |
parent | 5e65f7a40ded1827be1317ee09fc65174cb673c2 (diff) |
s/renderer: Pass output_cache in constructor
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file/file_default.php | 4 | ||||
-rw-r--r-- | application/service/renderer.php | 25 |
2 files changed, 16 insertions, 13 deletions
diff --git a/application/controllers/file/file_default.php b/application/controllers/file/file_default.php index 826e3f4af..2a26c380c 100644 --- a/application/controllers/file/file_default.php +++ b/application/controllers/file/file_default.php @@ -225,8 +225,8 @@ class File_default extends MY_Controller { $output_cache->add(array("filedata" => $filedata), "file/fragments/asciinema-player"); } else { $output_cache->add_function(function() use ($output_cache, $filedata, $lexer, $is_multipaste) { - $renderer = new \service\renderer($this->mfile, $this->data); - $renderer->highlight_file($output_cache, $filedata, $lexer, $is_multipaste); + $renderer = new \service\renderer($output_cache, $this->mfile, $this->data); + $renderer->highlight_file($filedata, $lexer, $is_multipaste); }); } } diff --git a/application/service/renderer.php b/application/service/renderer.php index c6e58165b..66b6779a2 100644 --- a/application/service/renderer.php +++ b/application/service/renderer.php @@ -12,15 +12,18 @@ class renderer { /** - * @param mixed $mfile + * @param $output_cache output cache object + * @param $mfile mfile object + * @param $data data for the rendering of views */ - public function __construct($mfile, $data) + public function __construct($output_cache, $mfile, $data) { + $this->output_cache = $output_cache; $this->mfile = $mfile; $this->data = $data; } - private function colorify($output_cache, $file, $lexer, $anchor_id = false) + private function colorify($file, $lexer, $anchor_id = false) { $output = ""; $lines_to_remove = 0; @@ -37,7 +40,7 @@ class renderer { $pretty_json = json_encode($decoded_json, JSON_PRETTY_PRINT); if ($pretty_json !== false) { $content = $pretty_json; - $output_cache->render_now( + $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>" @@ -106,12 +109,12 @@ class renderer { ); } - public function highlight_file($output_cache, $filedata, $lexer, $is_multipaste) + public function highlight_file($filedata, $lexer, $is_multipaste) { // highlight the file and cache the result, fall back to plain text if $lexer fails foreach (array($lexer, "text") as $lexer) { $highlit = cache_function($filedata['data_id'].'_'.$lexer, 100, - function() use ($output_cache, $filedata, $lexer, $is_multipaste) { + function() use ($filedata, $lexer, $is_multipaste) { $file = $this->mfile->file($filedata['data_id']); if ($lexer == "rmd") { ob_start(); @@ -131,7 +134,7 @@ class renderer { "return_value" => 0, ); } else { - return $this->colorify($output_cache, $file, $lexer, $is_multipaste ? $filedata["id"] : false); + return $this->colorify($file, $lexer, $is_multipaste ? $filedata["id"] : false); } }); @@ -142,7 +145,7 @@ class renderer { if ($lexer != "text") { $message .= " Falling back to plain text."; } - $output_cache->render_now( + $this->output_cache->render_now( array("error_message" => "<p>$message</p>"), "file/fragments/alert-wide" ); @@ -157,9 +160,9 @@ class renderer { 'filedata' => $filedata, )); - $output_cache->render_now($data, 'file/html_paste_header'); - $output_cache->render_now($highlit["output"]); - $output_cache->render_now($data, 'file/html_paste_footer'); + $this->output_cache->render_now($data, 'file/html_paste_header'); + $this->output_cache->render_now($highlit["output"]); + $this->output_cache->render_now($data, 'file/html_paste_footer'); } |