-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBytes.php
53 lines (44 loc) · 1.07 KB
/
Bytes.php
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
<?php
namespace Bolt\packstream;
use ArrayAccess, Countable, Stringable;
/**
* Class Bytes
*
* @author Michal Stefanak
* @link https://github.com/neo4j-php/Bolt
* @link https://www.neo4j.com/docs/bolt/current/packstream/#data-type-bytes
* @package Bolt\packstream
*/
class Bytes implements ArrayAccess, Countable, Stringable
{
public function __construct(private array $bytes = [])
{
}
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->bytes);
}
public function offsetGet($offset): ?string
{
return $this->bytes[$offset] ?? null;
}
public function offsetSet($offset, $value): void
{
if ($offset === null)
$this->bytes[] = $value;
else
$this->bytes[$offset] = $value;
}
public function offsetUnset($offset): void
{
unset($this->bytes[$offset]);
}
public function count(): int
{
return count($this->bytes);
}
public function __toString(): string
{
return implode($this->bytes);
}
}