Skip to content

Commit a6593ec

Browse files
Update Http Server to use new WritableConnection implementation (#5572)
Co-authored-by: 李铭昕 <[email protected]>
1 parent 48a8d65 commit a6593ec

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=8.0",
14+
"hyperf/engine": "^1.9|^2.7",
1415
"hyperf/utils": "~3.0.0",
1516
"laminas/laminas-mime": "^2.7",
1617
"psr/http-message": "^1.0"

src/Server/Chunk/HasChunk.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Server\Chunk;
1313

14+
use Hyperf\Engine\Contract\Http\Writable;
15+
1416
trait HasChunk
1517
{
1618
public function write(string $content): bool
1719
{
18-
if (isset($this->connection) && $this->connection instanceof Chunkable) {
20+
if (isset($this->connection) && $this->connection instanceof Writable) {
1921
return $this->connection->write($content);
2022
}
2123

src/Server/Connection/SwooleConnection.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Server\Connection;
1313

14+
use Hyperf\Engine\Http\WritableConnection;
1415
use Hyperf\HttpMessage\Server\Chunk\Chunkable;
1516
use Hyperf\HttpMessage\Server\ConnectionInterface;
16-
use Swoole\Http\Response;
1717

18-
class SwooleConnection implements ConnectionInterface, Chunkable
18+
/**
19+
* @deprecated since 3.1.0, please use `Hyperf\Engine\Http\WritableConnection` instead.
20+
*/
21+
class SwooleConnection extends WritableConnection implements ConnectionInterface, Chunkable
1922
{
20-
public function __construct(protected Response $response)
21-
{
22-
}
23-
24-
public function write(string $data): bool
25-
{
26-
return $this->response->write($data);
27-
}
28-
29-
public function getSocket(): mixed
30-
{
31-
return $this->response;
32-
}
3323
}

src/Server/ConnectionInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Server;
1313

14+
/**
15+
* @deprecated since 3.1.0, please use `Hyperf\Engine\Contract\Http\Writable` instead.
16+
*/
1417
interface ConnectionInterface
1518
{
1619
/**

src/Server/Response.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\HttpMessage\Server;
1313

14+
use Hyperf\Engine\Contract\Http\Writable;
1415
use Hyperf\HttpMessage\Cookie\Cookie;
1516
use Hyperf\HttpMessage\Server\Chunk\Chunkable;
1617
use Hyperf\HttpMessage\Server\Chunk\HasChunk;
@@ -24,7 +25,7 @@ class Response extends \Hyperf\HttpMessage\Base\Response implements Chunkable
2425

2526
protected array $trailers = [];
2627

27-
protected ?ConnectionInterface $connection = null;
28+
protected ?Writable $connection = null;
2829

2930
/**
3031
* Returns an instance with body content.
@@ -81,13 +82,13 @@ public function getTrailers(): array
8182
return $this->trailers;
8283
}
8384

84-
public function setConnection(ConnectionInterface $connection)
85+
public function setConnection(ConnectionInterface|Writable $connection)
8586
{
8687
$this->connection = $connection;
8788
return $this;
8889
}
8990

90-
public function getConnection(): ?ConnectionInterface
91+
public function getConnection(): ConnectionInterface|Writable|null
9192
{
9293
return $this->connection;
9394
}

0 commit comments

Comments
 (0)