modify
This commit is contained in:
@@ -69,21 +69,6 @@ class Response extends HttpService
|
|||||||
$this->format = null;
|
$this->format = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getContentType(): string
|
|
||||||
{
|
|
||||||
if ($this->format == null || $this->format == static::JSON) {
|
|
||||||
return 'application/json;charset=utf-8';
|
|
||||||
} else if ($this->format == static::XML) {
|
|
||||||
return 'application/xml;charset=utf-8';
|
|
||||||
} else {
|
|
||||||
return 'text/html;charset=utf-8';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $content
|
* @param $content
|
||||||
* @return string
|
* @return string
|
||||||
@@ -91,7 +76,12 @@ class Response extends HttpService
|
|||||||
public function toHtml($content): string
|
public function toHtml($content): string
|
||||||
{
|
{
|
||||||
$this->format = self::HTML;
|
$this->format = self::HTML;
|
||||||
return (string)$content;
|
|
||||||
|
/** @var SResponse $response */
|
||||||
|
$response = Context::getContext(SResponse::class);
|
||||||
|
$response->header('Content-Type','text/html;charset=utf-8');
|
||||||
|
|
||||||
|
return (string)$content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +92,12 @@ class Response extends HttpService
|
|||||||
public function toJson($content): string|bool
|
public function toJson($content): string|bool
|
||||||
{
|
{
|
||||||
$this->format = self::JSON;
|
$this->format = self::JSON;
|
||||||
return json_encode($content, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
/** @var SResponse $response */
|
||||||
|
$response = Context::getContext(SResponse::class);
|
||||||
|
$response->header('Content-Type','application/json;charset=utf-8');
|
||||||
|
|
||||||
|
return json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,7 +108,12 @@ class Response extends HttpService
|
|||||||
public function toXml($content): mixed
|
public function toXml($content): mixed
|
||||||
{
|
{
|
||||||
$this->format = self::XML;
|
$this->format = self::XML;
|
||||||
return $content;
|
|
||||||
|
/** @var SResponse $response */
|
||||||
|
$response = Context::getContext(SResponse::class);
|
||||||
|
$response->header('Content-Type','application/xml;charset=utf-8');
|
||||||
|
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,13 +217,19 @@ class Response extends HttpService
|
|||||||
*/
|
*/
|
||||||
private function sendData($sendData): void
|
private function sendData($sendData): void
|
||||||
{
|
{
|
||||||
|
/** @var SResponse $response */
|
||||||
$response = Context::getContext(SResponse::class);
|
$response = Context::getContext(SResponse::class);
|
||||||
if (!$response?->isWritable()) {
|
if (!$response?->isWritable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->setCookies($response);
|
$this->setCookies($response);
|
||||||
defer(fn() => $this->headers = []);
|
defer(fn() => $this->headers = []);
|
||||||
$response->header('Content-Type', $this->getContentType());
|
|
||||||
|
var_dump($response);
|
||||||
|
|
||||||
|
// $response->header['']
|
||||||
|
//
|
||||||
|
// $response->header('Content-Type', $this->getContentType());
|
||||||
$response->header('Run-Time', $this->getRuntime());
|
$response->header('Run-Time', $this->getRuntime());
|
||||||
foreach ($this->headers as $key => $header) {
|
foreach ($this->headers as $key => $header) {
|
||||||
$response->header($key, $header);
|
$response->header($key, $header);
|
||||||
|
|||||||
Reference in New Issue
Block a user