Skip to content

Commit f3e6960

Browse files
committed
feat(ws): using standard http codes
1 parent 7170035 commit f3e6960

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
],
1717
"require": {
1818
"php": ">=8.1",
19-
"guzzlehttp/psr7": "^2.0"
19+
"guzzlehttp/psr7": "^2.0",
20+
"ahmard/http-status-codes": "^1.0"
2021
},
2122
"scripts": {
2223
"analyse": "phpstan analyse",

src/Websocket/ConnectionInterface.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace RTC\Contracts\Websocket;
44

5+
use HttpStatusCodes\StatusCode;
56
use RTC\Contracts\Enums\WSSenderType;
67

78
interface ConnectionInterface
@@ -16,8 +17,7 @@ public function __construct(int $fd);
1617
* @param array $meta
1718
* @param WSSenderType $senderType
1819
* @param string $senderId
19-
* @param int $status
20-
* @param string $statusText
20+
* @param StatusCode $status
2121
* @param int $opcode
2222
* @param int $flags
2323
* @return void
@@ -28,8 +28,7 @@ public function send(
2828
array $meta = [],
2929
WSSenderType $senderType = WSSenderType::SERVER,
3030
string $senderId = 'system',
31-
int $status = 200,
32-
string $statusText = 'success',
31+
StatusCode $status = StatusCode::OK,
3332
int $opcode = 1,
3433
int $flags = SWOOLE_WEBSOCKET_FLAG_FIN
3534
): void;

src/Websocket/RoomInterface.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace RTC\Contracts\Websocket;
44

5+
use HttpStatusCodes\StatusCode;
56
use RTC\Contracts\Server\ServerInterface;
67
use Swoole\Table;
78

@@ -69,19 +70,17 @@ public function getMetaData(int|ConnectionInterface $connection): ?array;
6970
/**
7071
* @param string $event
7172
* @param mixed $message
72-
* @param int $status
73-
* @param string $statusText
7473
* @param array $meta
7574
* @param array $excludeIds
75+
* @param StatusCode $status
7676
* @return int
7777
*/
7878
public function send(
79-
string $event,
80-
mixed $message,
81-
int $status = 200,
82-
string $statusText = 'success',
83-
array $meta = [],
84-
array $excludeIds = []
79+
string $event,
80+
mixed $message,
81+
array $meta = [],
82+
array $excludeIds = [],
83+
StatusCode $status = StatusCode::OK,
8584
): int;
8685

8786
/**

0 commit comments

Comments
 (0)