From e17cf68007931f39282840e30dafe351720cbd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 5 Jul 2020 00:25:34 +0200 Subject: [PATCH] MAPG-191 don't pass data by reference to IContent --- src/Interfaces/Response/IContent.php | 4 +++- src/Response/ContentBase.php | 7 ++++++- src/Response/HtmlContent.php | 4 ++-- src/Response/JsonContent.php | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Interfaces/Response/IContent.php b/src/Interfaces/Response/IContent.php index fef4842..c93e94b 100644 --- a/src/Interfaces/Response/IContent.php +++ b/src/Interfaces/Response/IContent.php @@ -2,7 +2,9 @@ interface IContent { - public function &getData(): array; + public function setData(array $data): void; + + public function getData(): array; public function render(): void; diff --git a/src/Response/ContentBase.php b/src/Response/ContentBase.php index 31d0053..10cfafc 100644 --- a/src/Response/ContentBase.php +++ b/src/Response/ContentBase.php @@ -6,7 +6,12 @@ abstract class ContentBase implements IContent { protected array $data; - public function &getData(): array + public function setData(array $data): void + { + $this->data = $data; + } + + public function getData(): array { return $this->data; } diff --git a/src/Response/HtmlContent.php b/src/Response/HtmlContent.php index b5c9d6c..377b32e 100644 --- a/src/Response/HtmlContent.php +++ b/src/Response/HtmlContent.php @@ -6,10 +6,10 @@ class HtmlContent extends ContentBase { private string $view; - public function __construct(string $view, array &$data = []) + public function __construct(string $view, array $data = []) { $this->view = $view; - $this->data = &$data; + $this->data = $data; } public function render(): void diff --git a/src/Response/JsonContent.php b/src/Response/JsonContent.php index c2ecac0..9632328 100644 --- a/src/Response/JsonContent.php +++ b/src/Response/JsonContent.php @@ -2,9 +2,9 @@ class JsonContent extends ContentBase { - public function __construct(array &$data = []) + public function __construct(array $data = []) { - $this->data = &$data; + $this->data = $data; } public function render(): void