|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\AMQP\Transport\Frame\{ |
|
7
|
|
|
Type, |
|
8
|
|
|
Channel, |
|
9
|
|
|
Method, |
|
10
|
|
|
Value, |
|
11
|
|
|
Value\UnsignedOctet, |
|
12
|
|
|
Value\UnsignedShortInteger, |
|
13
|
|
|
Value\UnsignedLongInteger |
|
14
|
|
|
}; |
|
15
|
|
|
use Innmind\Math\Algebra\Integer; |
|
16
|
|
|
use Innmind\Immutable\{ |
|
17
|
|
|
Sequence, |
|
18
|
|
|
Stream, |
|
19
|
|
|
StreamInterface |
|
20
|
|
|
}; |
|
21
|
|
|
|
|
22
|
|
|
final class Frame |
|
23
|
|
|
{ |
|
24
|
|
|
private $type; |
|
25
|
|
|
private $channel; |
|
26
|
|
|
private $method; |
|
27
|
|
|
private $values; |
|
28
|
|
|
private $string; |
|
29
|
|
|
|
|
30
|
1 |
|
public function __construct( |
|
31
|
|
|
Type $type, |
|
32
|
|
|
Channel $channel, |
|
33
|
|
|
Method $method, |
|
34
|
|
|
Value ...$values |
|
35
|
|
|
) { |
|
36
|
1 |
|
$this->type = $type; |
|
37
|
1 |
|
$this->channel = $channel; |
|
38
|
1 |
|
$this->method = $method; |
|
39
|
1 |
|
$values = new Sequence(...$values); |
|
40
|
1 |
|
$payload = $values->join('')->toEncoding('ASCII'); |
|
41
|
1 |
|
$frame = new Sequence( |
|
42
|
1 |
|
new UnsignedOctet(new Integer($type->toInt())), |
|
43
|
1 |
|
new UnsignedShortInteger(new Integer($channel->toInt())), |
|
44
|
1 |
|
new UnsignedLongInteger( |
|
45
|
1 |
|
new Integer($payload->length() + 4) // 4 is the size for the method |
|
46
|
|
|
), |
|
47
|
1 |
|
new UnsignedShortInteger(new Integer($method->class())), |
|
48
|
1 |
|
new UnsignedShortInteger(new Integer($method->method())), |
|
49
|
1 |
|
$payload, |
|
50
|
1 |
|
new UnsignedOctet(new Integer(0xCE)) |
|
51
|
|
|
); |
|
52
|
1 |
|
$this->values = $values->reduce( |
|
53
|
1 |
|
new Stream(Value::class), |
|
54
|
1 |
|
static function(Stream $stream, Value $value): Stream { |
|
55
|
1 |
|
return $stream->add($value); |
|
|
|
|
|
|
56
|
1 |
|
} |
|
57
|
|
|
); |
|
58
|
1 |
|
$this->string = (string) $frame->join(''); |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function type(): Type |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->type; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function channel(): Channel |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->channel; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function method(): Method |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->method; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return StreamInterface<Value> |
|
|
|
|
|
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function values(): StreamInterface |
|
80
|
|
|
{ |
|
81
|
1 |
|
return $this->values; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function __toString(): string |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->string; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: