1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Frame\Value; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Transport\Frame\Value, |
8
|
|
|
Exception\OutOfRangeValue, |
9
|
|
|
Exception\StringNotOfExpectedLength |
10
|
|
|
}; |
11
|
|
|
use Innmind\Math\{ |
12
|
|
|
Algebra\Integer, |
13
|
|
|
Algebra\Number\Infinite, |
14
|
|
|
DefinitionSet\Set, |
15
|
|
|
DefinitionSet\Range, |
16
|
|
|
DefinitionSet\Integers |
17
|
|
|
}; |
18
|
|
|
use Innmind\Immutable\Str; |
19
|
|
|
|
20
|
|
|
final class UnsignedLongLongInteger implements Value |
21
|
|
|
{ |
22
|
|
|
private static $definitionSet; |
23
|
|
|
|
24
|
|
|
private $value; |
25
|
|
|
private $original; |
26
|
|
|
|
27
|
15 |
|
public function __construct(Integer $value) |
28
|
|
|
{ |
29
|
15 |
|
if (!self::definitionSet()->contains($value)) { |
30
|
1 |
|
throw new OutOfRangeValue($value, self::definitionSet()); |
31
|
|
|
} |
32
|
|
|
|
33
|
14 |
|
$this->value = pack('J', $value->value()); |
34
|
14 |
|
$this->original = $value; |
35
|
14 |
|
} |
36
|
|
|
|
37
|
7 |
|
public static function fromString(Str $string): Value |
38
|
|
|
{ |
39
|
7 |
|
$string = $string->toEncoding('ASCII'); |
40
|
|
|
|
41
|
7 |
|
if ($string->length() !== 8) { |
42
|
1 |
|
throw new StringNotOfExpectedLength($string, 8); |
43
|
|
|
} |
44
|
|
|
|
45
|
6 |
|
[, $value] = unpack('J', (string) $string); |
|
|
|
|
46
|
|
|
|
47
|
6 |
|
return new self(new Integer($value)); |
48
|
|
|
} |
49
|
|
|
|
50
|
6 |
|
public static function cut(Str $string): Str |
51
|
|
|
{ |
52
|
6 |
|
return $string->toEncoding('ASCII')->substring(0, 8); |
53
|
|
|
} |
54
|
|
|
|
55
|
11 |
|
public function original(): Integer |
56
|
|
|
{ |
57
|
11 |
|
return $this->original; |
58
|
|
|
} |
59
|
|
|
|
60
|
13 |
|
public function __toString(): string |
61
|
|
|
{ |
62
|
13 |
|
return $this->value; |
63
|
|
|
} |
64
|
|
|
|
65
|
15 |
|
public static function definitionSet(): Set |
66
|
|
|
{ |
67
|
15 |
|
return self::$definitionSet ?? self::$definitionSet = Range::inclusive( |
68
|
|
|
new Integer(0), |
69
|
|
|
Infinite::positive() |
70
|
15 |
|
)->intersect(new Integers); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.