1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Model\Exchange\Declaration, |
8
|
|
|
Model\Exchange\Deletion, |
9
|
|
|
Transport\Frame, |
10
|
|
|
Transport\Frame\Channel as FrameChannel, |
11
|
|
|
Transport\Frame\Type, |
12
|
|
|
Transport\Frame\Value, |
13
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
14
|
|
|
Transport\Frame\Value\ShortString, |
15
|
|
|
Transport\Frame\Value\Bits, |
16
|
|
|
Transport\Frame\Value\Table, |
17
|
|
|
Transport\Protocol\Exchange as ExchangeInterface, |
18
|
|
|
Transport\Protocol\ArgumentTranslator, |
19
|
|
|
}; |
20
|
|
|
use Innmind\Math\Algebra\Integer; |
21
|
|
|
use Innmind\Immutable\{ |
22
|
|
|
Str, |
23
|
|
|
Map, |
24
|
|
|
}; |
25
|
|
|
|
26
|
|
|
final class Exchange implements ExchangeInterface |
27
|
|
|
{ |
28
|
|
|
private $translate; |
29
|
|
|
|
30
|
244 |
|
public function __construct(ArgumentTranslator $translator) |
31
|
|
|
{ |
32
|
244 |
|
$this->translate = $translator; |
33
|
244 |
|
} |
34
|
|
|
|
35
|
4 |
|
public function declare(FrameChannel $channel, Declaration $command): Frame |
36
|
|
|
{ |
37
|
4 |
|
return Frame::method( |
38
|
4 |
|
$channel, |
39
|
4 |
|
Methods::get('exchange.declare'), |
40
|
4 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
41
|
4 |
|
ShortString::of(new Str($command->name())), |
42
|
4 |
|
ShortString::of(new Str((string) $command->type())), |
43
|
4 |
|
new Bits( |
44
|
4 |
|
$command->isPassive(), |
45
|
4 |
|
$command->isDurable(), |
46
|
4 |
|
$command->isAutoDeleted(), //reserved |
47
|
4 |
|
false, //internal (reserved) |
48
|
4 |
|
!$command->shouldWait() |
49
|
|
|
), |
50
|
4 |
|
new Table( |
51
|
|
|
$command |
52
|
4 |
|
->arguments() |
53
|
4 |
|
->reduce( |
54
|
4 |
|
new Map('string', Value::class), |
55
|
|
|
function(Map $carry, string $key, $value): Map { |
56
|
2 |
|
return $carry->put( |
57
|
2 |
|
$key, |
58
|
2 |
|
($this->translate)($value) |
59
|
|
|
); |
60
|
4 |
|
} |
61
|
|
|
) |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
4 |
|
public function delete(FrameChannel $channel, Deletion $command): Frame |
67
|
|
|
{ |
68
|
4 |
|
return Frame::method( |
69
|
4 |
|
$channel, |
70
|
4 |
|
Methods::get('exchange.delete'), |
71
|
4 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
72
|
4 |
|
ShortString::of(new Str($command->name())), |
73
|
4 |
|
new Bits( |
74
|
4 |
|
$command->onlyIfUnused(), |
75
|
4 |
|
!$command->shouldWait() |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|