diff --git a/composer.json b/composer.json index 91d6ed8..8667c0d 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,12 @@ }, "require": { "php": ">=8.1", + "hyperf/context": "~3.1.0", "hyperf/contract": "~3.1.0", "hyperf/support": "~3.1.0", "hyperf/utils": "~3.1.0", - "psr/container": "^1.0|^2.0" + "psr/container": "^1.0|^2.0", + "swow/psr7-plus": "^1.0" }, "suggest": { "hyperf/task": "Required to use task as a view render mode.", diff --git a/src/Render.php b/src/Render.php index 088dc3b..1cc0922 100644 --- a/src/Render.php +++ b/src/Render.php @@ -11,7 +11,7 @@ */ namespace Hyperf\View; -use Hyperf\Context\Context; +use Hyperf\Context\ResponseContext; use Hyperf\Contract\ConfigInterface; use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\Task\Task; @@ -46,9 +46,9 @@ public function __construct(protected ContainerInterface $container, ConfigInter public function render(string $template, array $data = []): ResponseInterface { - return $this->response() - ->withAddedHeader('content-type', $this->getContentType()) - ->withBody(new SwooleStream($this->getContents($template, $data))); + return ResponseContext::get() + ->addHeader('content-type', $this->getContentType()) + ->setBody(new SwooleStream($this->getContents($template, $data))); } public function getContents(string $template, array $data = []): string @@ -79,9 +79,4 @@ public function getContentType(): string return 'text/html' . $charset; } - - protected function response(): ResponseInterface - { - return Context::get(ResponseInterface::class); - } }