Repository navigation
Expand file tree
/
Copy pathPacket.php
More file actions
76 lines (58 loc) · 1.53 KB
/
Copy pathPacket.php
File metadata and controls
76 lines (58 loc) · 1.53 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\SocketIOServer\Parser;
use ArrayAccess;
class Packet implements ArrayAccess
{
public const OPEN = '0';
public const CLOSE = '1';
public const EVENT = '2';
public const ACK = '3';
public string $id;
public string $type;
public string $nsp;
public ?array $data = null;
public mixed $query;
private function __construct()
{
}
public static function create(array $decoded)
{
$new = new Packet();
$new->id = (string) ($decoded['id'] ?? '');
$new->type = (string) $decoded['type'];
if (isset($decoded['nsp'])) {
$new->nsp = (string) ($decoded['nsp'] ?: '/');
} else {
$new->nsp = '/';
}
$data = $decoded['data'] ?? null;
$new->data = is_array($data) ? $data : null;
$new->query = $decoded['query'] ?? null;
return $new;
}
public function offsetExists(mixed $offset): bool
{
return isset($this->{$offset});
}
public function offsetGet(mixed $offset): mixed
{
return $this->{$offset};
}
public function offsetSet(mixed $offset, mixed $value): void
{
$this->{$offset} = $value;
}
public function offsetUnset(mixed $offset): void
{
unset($this->{$offset});
}
}