Skip to content

Commit

Permalink
Support swow psr7-plus interface for all components. (#5839)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo authored Jun 16, 2023
1 parent 640c6c1 commit f089e1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
13 changes: 4 additions & 9 deletions src/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -79,9 +79,4 @@ public function getContentType(): string

return 'text/html' . $charset;
}

protected function response(): ResponseInterface
{
return Context::get(ResponseInterface::class);
}
}

0 comments on commit f089e1c

Please sign in to comment.