parent
da1b58fb05
commit
eb364c285b
@ -0,0 +1,63 @@ |
|||||||
|
<?php |
||||||
|
// SPDX-License-Identifier: EUPL-1.2 |
||||||
|
// Authors: see README.md |
||||||
|
|
||||||
|
namespace SeaCMS\App; |
||||||
|
|
||||||
|
use SeaCMS\Api\JsonResponse; |
||||||
|
|
||||||
|
/** |
||||||
|
* Response for http response |
||||||
|
*/ |
||||||
|
class MdResponse extends JsonResponse |
||||||
|
{ |
||||||
|
/** |
||||||
|
* content as string |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
protected $stringContent; |
||||||
|
|
||||||
|
public function __construct(int $code, string $content, array $headers = [],?Cookies $cookies = null){ |
||||||
|
parent::__construct($code,[],[],$cookies); |
||||||
|
$this->stringContent = $content; |
||||||
|
$this->headers = array_merge([ |
||||||
|
'Content-Type' => 'text/markdown', |
||||||
|
'Access-Control-Allow-Origin' => '*', |
||||||
|
'Access-Control-Allow-Credentials' => 'true', |
||||||
|
'Access-Control-Allow-Headers' => 'X-Requested-With, Location, Slug, Accept, Content-Type', |
||||||
|
'Access-Control-Expose-Headers' => 'Location, Slug, Accept, Content-Type', |
||||||
|
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, DELETE, PUT, PATCH', |
||||||
|
'Access-Control-Max-Age' => '86400' |
||||||
|
], $headers); |
||||||
|
} |
||||||
|
|
||||||
|
/* === Getters === */ |
||||||
|
/** |
||||||
|
* return stringContent |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getStringContent(): string |
||||||
|
{ |
||||||
|
return $this->stringContent; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* return content as String |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function returnContent(): string |
||||||
|
{ |
||||||
|
return $this->getStringContent(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* export class as array |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function jsonSerialize(): mixed |
||||||
|
{ |
||||||
|
return array_merge(parent::jsonSerialize(),[ |
||||||
|
'stringContent' => $this->getStringContent() |
||||||
|
]); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue