Formats: Remove display & related method (#2776)

Format should not be responsible for sending HTTP response.
This commit is contained in:
Jan Tojnar 2022-06-07 18:05:33 +02:00 committed by GitHub
parent e85932b1a5
commit fb501652d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 11 additions and 178 deletions

View file

@ -24,9 +24,6 @@ abstract class FormatAbstract implements FormatInterface {
/** MIME type of format output */
const MIME_TYPE = 'text/plain';
/** @var string|null $contentType The content type */
protected $contentType = null;
/** @var string $charset The charset */
protected $charset;
@ -65,18 +62,6 @@ abstract class FormatAbstract implements FormatInterface {
return is_null($charset) ? static::DEFAULT_CHARSET : $charset;
}
/**
* Set the content type
*
* @param string $contentType The content type
* @return self The format object
*/
protected function setContentType($contentType){
$this->contentType = $contentType;
return $this;
}
/**
* Set the last modified time
*
@ -87,34 +72,6 @@ abstract class FormatAbstract implements FormatInterface {
$this->lastModified = $lastModified;
}
/**
* Send header with the currently specified content type
*
* @throws \LogicException if the content type is not set
* @throws \LogicException if the content type is not a string
*
* @return void
*/
protected function callContentType(){
if(empty($this->contentType))
throw new \LogicException('Content-Type is not set!');
if(!is_string($this->contentType))
throw new \LogicException('Content-Type must be a string!');
header('Content-Type: ' . $this->contentType);
}
/** {@inheritdoc} */
public function display(){
if ($this->lastModified) {
header('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $this->lastModified) . 'GMT');
}
echo $this->stringify();
return $this;
}
/**
* {@inheritdoc}
*