From a55ece7dacf4b17ebafb96c3aaaa1116c797a715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 27 Jun 2020 12:56:47 +0200 Subject: [PATCH] MAPG-180 don't buffer content output to variable --- src/Interfaces/Response/IContent.php | 2 +- src/Response/ContentBase.php | 2 +- src/Response/HtmlContent.php | 9 ++------- src/Response/JsonContent.php | 6 ++---- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Interfaces/Response/IContent.php b/src/Interfaces/Response/IContent.php index 446a4ab..fef4842 100644 --- a/src/Interfaces/Response/IContent.php +++ b/src/Interfaces/Response/IContent.php @@ -4,7 +4,7 @@ interface IContent { public function &getData(): array; - public function &render(): string; + public function render(): void; public function getContentType(): string; } diff --git a/src/Response/ContentBase.php b/src/Response/ContentBase.php index 359cbdb..31d0053 100644 --- a/src/Response/ContentBase.php +++ b/src/Response/ContentBase.php @@ -11,7 +11,7 @@ abstract class ContentBase implements IContent return $this->data; } - abstract public function &render(): string; + abstract public function render(): void; abstract public function getContentType(): string; } diff --git a/src/Response/HtmlContent.php b/src/Response/HtmlContent.php index 2e1b13e..b5c9d6c 100644 --- a/src/Response/HtmlContent.php +++ b/src/Response/HtmlContent.php @@ -12,7 +12,7 @@ class HtmlContent extends ContentBase $this->data = &$data; } - public function &render(): string + public function render(): void { if (!empty($_ENV['DEV'])) { $generator = new Linker($this->view); @@ -21,14 +21,9 @@ class HtmlContent extends ContentBase extract($this->data); - ob_start(); require ROOT . '/cache/views/' . $this->view . '.php'; - $content = ob_get_contents(); - ob_end_clean(); - $content .= ''; - - return $content; + echo ''; } public function getContentType(): string diff --git a/src/Response/JsonContent.php b/src/Response/JsonContent.php index d71eab8..c2ecac0 100644 --- a/src/Response/JsonContent.php +++ b/src/Response/JsonContent.php @@ -7,13 +7,11 @@ class JsonContent extends ContentBase $this->data = &$data; } - public function &render(): string + public function render(): void { $this->data['__debug__runtime'] = round((hrtime(true) - SCRIPT_STARTED) / 1e+6, 1); - $content = json_encode($this->data); - - return $content; + echo json_encode($this->data); } public function getContentType(): string