1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Transport\Protocol, |
8
|
|
|
Transport\Frame\Method, |
9
|
|
|
Exception\VersionNotUsable |
10
|
|
|
}; |
11
|
|
|
use Innmind\Immutable\{ |
12
|
|
|
Sequence, |
13
|
|
|
Str, |
14
|
|
|
StreamInterface |
15
|
|
|
}; |
16
|
|
|
|
17
|
|
|
final class Delegate implements Protocol |
18
|
|
|
{ |
19
|
|
|
private $protocols; |
20
|
|
|
private $inUse; |
21
|
|
|
|
22
|
|
|
public function __construct(Protocol $first, Protocol ...$protocols) |
23
|
|
|
{ |
24
|
4 |
|
$protocols = (new Sequence($first, ...$protocols))->sort(static function(Protocol $a, Protocol $b): bool { |
25
|
3 |
|
return $b->version()->higherThan($a->version()); |
|
|
|
|
26
|
4 |
|
}); |
27
|
4 |
|
$this->inUse = $protocols->first(); |
28
|
4 |
|
$this->protocols = $protocols; |
29
|
4 |
|
} |
30
|
|
|
|
31
|
3 |
|
public function version(): Version |
32
|
|
|
{ |
33
|
3 |
|
return $this->inUse->version(); |
34
|
|
|
} |
35
|
|
|
|
36
|
2 |
|
public function use(Version $version): Protocol |
37
|
|
|
{ |
38
|
|
|
$protocols = $this |
39
|
2 |
|
->protocols |
40
|
2 |
|
->filter(static function(Protocol $protocol) use ($version): bool { |
41
|
|
|
try { |
42
|
2 |
|
$protocol->use($version); |
43
|
|
|
|
44
|
2 |
|
return true; |
45
|
2 |
|
} catch (VersionNotUsable $e) { |
46
|
2 |
|
return false; |
47
|
|
|
} |
48
|
2 |
|
}); |
49
|
|
|
|
50
|
2 |
|
if ($protocols->size() === 0) { |
51
|
|
|
throw new VersionNotUsable($version); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
$this->inUse = $protocols->first(); |
55
|
|
|
|
56
|
2 |
|
return $this; |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function read(Method $method, Str $arguments): StreamInterface |
63
|
|
|
{ |
64
|
1 |
|
return $this->inUse->read($method, $arguments); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function method(string $name): Method |
68
|
|
|
{ |
69
|
1 |
|
return $this->inUse->method($name); |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
public function connection(): Connection |
73
|
|
|
{ |
74
|
1 |
|
return $this->inUse->connection(); |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
public function channel(): Channel |
78
|
|
|
{ |
79
|
1 |
|
return $this->inUse->channel(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function exchange(): Exchange |
83
|
|
|
{ |
84
|
|
|
return $this->inUse->exchange(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function queue(): Queue |
88
|
|
|
{ |
89
|
|
|
return $this->inUse->queue(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function basic(): Basic |
93
|
|
|
{ |
94
|
|
|
return $this->inUse->basic(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function transaction(): Transaction |
98
|
|
|
{ |
99
|
|
|
return $this->inUse->transaction(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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: