-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrame.php
More file actions
50 lines (40 loc) · 1.26 KB
/
Copy pathFrame.php
File metadata and controls
50 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Micilini\PhpSockets\Protocol;
final readonly class Frame
{
public function __construct(
public bool $fin,
public Opcode $opcode,
public string $payload = '',
public bool $masked = false,
) {
$payloadLength = strlen($this->payload);
if ($this->opcode->isControl() && !$this->fin) {
throw new ProtocolException('Control frames must not be fragmented.');
}
if ($this->opcode->isControl() && $payloadLength > 125) {
throw new ProtocolException('Control frame payload cannot be larger than 125 bytes.');
}
}
public static function text(string $payload): self
{
return new self(true, Opcode::TEXT, $payload);
}
public static function binary(string $payload): self
{
return new self(true, Opcode::BINARY, $payload);
}
public static function close(string $payload = ''): self
{
return new self(true, Opcode::CLOSE, $payload);
}
public static function ping(string $payload = ''): self
{
return new self(true, Opcode::PING, $payload);
}
public static function pong(string $payload = ''): self
{
return new self(true, Opcode::PONG, $payload);
}
}