2022-12-26 19:10:28 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Choir\WebSocket;
|
|
|
|
|
|
|
|
|
|
class FrameFactory
|
|
|
|
|
{
|
|
|
|
|
public static function createPingFrame(): Frame
|
|
|
|
|
{
|
|
|
|
|
return new Frame(null, Opcode::PING, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function createPongFrame(): Frame
|
|
|
|
|
{
|
|
|
|
|
return new Frame(null, Opcode::PONG, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function createTextFrame(string $payload): Frame
|
|
|
|
|
{
|
|
|
|
|
return new Frame($payload, Opcode::TEXT, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function createBinaryFrame(string $payload): Frame
|
|
|
|
|
{
|
|
|
|
|
return new Frame($payload, Opcode::BINARY, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-10 10:17:16 +08:00
|
|
|
public static function createCloseFrame(?int $code = null, ?string $reason = null): Frame
|
2022-12-26 19:10:28 +08:00
|
|
|
{
|
|
|
|
|
return new CloseFrame($code, $reason);
|
|
|
|
|
}
|
|
|
|
|
}
|