From fb501652d5ef8519470fa1faa585b3668ebd2a34 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Tue, 7 Jun 2022 18:05:33 +0200 Subject: [PATCH] Formats: Remove display & related method (#2776) Format should not be responsible for sending HTTP response. --- actions/DisplayAction.php | 10 ++++-- docs/08_Format_API/02_FormatInterface.md | 14 -------- docs/08_Format_API/03_FormatAbstract.md | 18 ---------- formats/AtomFormat.php | 8 ----- formats/HtmlFormat.php | 8 ----- formats/JsonFormat.php | 8 ----- formats/MrssFormat.php | 8 ----- formats/PlaintextFormat.php | 8 ----- lib/FormatAbstract.php | 43 ------------------------ lib/FormatInterface.php | 7 ---- tests/AtomFormatTest.php | 19 +---------- tests/JsonFormatTest.php | 19 +---------- tests/MrssFormatTest.php | 19 +---------- 13 files changed, 11 insertions(+), 178 deletions(-) diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index 99dd21ce..52853d36 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -244,8 +244,14 @@ class DisplayAction extends ActionAbstract { $format = $formatFac->create($format); $format->setItems($items); $format->setExtraInfos($infos); - $format->setLastModified($cache->getTime()); - $format->display(); + $lastModified = $cache->getTime(); + $format->setLastModified($lastModified); + if ($lastModified) { + header('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $lastModified) . 'GMT'); + } + header('Content-Type: ' . $format->getMimeType() . '; charset=' . $format->getCharset()); + + echo $format->stringify(); } catch(Error $e) { error_log($e); header('Content-Type: text/html', true, $e->getCode()); diff --git a/docs/08_Format_API/02_FormatInterface.md b/docs/08_Format_API/02_FormatInterface.md index 28ac60b3..88448c38 100644 --- a/docs/08_Format_API/02_FormatInterface.md +++ b/docs/08_Format_API/02_FormatInterface.md @@ -14,14 +14,6 @@ Find a [template](#template) at the end of this file # Functions -## The `display` function - -The `display` function shows the contents to the user and must return the object instance. - -```PHP -display(): self -``` - ## The `stringify` function The `stringify` function returns the items received by [`setItems`](#the-setitem-function) as string. @@ -109,12 +101,6 @@ class MyTypeFormat implements FormatInterface { return ''; // Return items as string } - public function display(){ - // Implement your code here - echo $this->stringify(); - return $this; - } - public function setItems(array $items){ $this->items = $items; return $this; diff --git a/docs/08_Format_API/03_FormatAbstract.md b/docs/08_Format_API/03_FormatAbstract.md index 82e42718..8cf0418f 100644 --- a/docs/08_Format_API/03_FormatAbstract.md +++ b/docs/08_Format_API/03_FormatAbstract.md @@ -1,27 +1,9 @@ The `FormatAbstract` class implements the [`FormatInterface`](../08_Format_API/02_FormatInterface.md) interface with basic functional behavior and adds common helper functions for new formats: -* [setContentType](#the-setcontenttype-function) -* [callContentType](#the-callcontenttype-function) * [sanitizeHtml](#the-sanitizehtml-function) # Functions -## The `setContentType` function - -The `setContentType` function receives a string defining the content type for the HTML header and must return the object instance. - -```PHP -setContentType(string): self -``` - -## The `callContentType` function - -The `callContentType` function applies the content type to the header data and must return the object instance. - -```PHP -callContentType(): self -``` - ## The `sanitizeHtml` function The `sanitizeHtml` function receives an HTML formatted string and returns the string with disabled `