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
|
82 |
|
public function __construct(ArgumentTranslator $translator) |
31
|
|
|
{ |
32
|
82 |
|
$this->translate = $translator; |
33
|
82 |
|
} |
34
|
|
|
|
35
|
2 |
|
public function declare(FrameChannel $channel, Declaration $command): Frame |
|
|
|
|
36
|
|
|
{ |
37
|
2 |
|
return new Frame( |
38
|
2 |
|
Type::method(), |
39
|
2 |
|
$channel, |
40
|
2 |
|
Methods::get('exchange.declare'), |
41
|
2 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
42
|
2 |
|
new ShortString(new Str($command->name())), |
43
|
2 |
|
new ShortString(new Str((string) $command->type())), |
44
|
2 |
|
new Bits( |
45
|
2 |
|
$command->isPassive(), |
46
|
2 |
|
$command->isDurable(), |
47
|
2 |
|
$command->isAutoDeleted(), //reserved |
48
|
2 |
|
false, //internal (reserved) |
49
|
2 |
|
!$command->shouldWait() |
50
|
|
|
), |
51
|
2 |
|
new Table( |
52
|
|
|
$command |
53
|
2 |
|
->arguments() |
54
|
2 |
|
->reduce( |
55
|
2 |
|
new Map('string', Value::class), |
56
|
2 |
|
function(Map $carry, string $key, $value): Map { |
57
|
1 |
|
return $carry->put( |
58
|
1 |
|
$key, |
59
|
1 |
|
($this->translate)($value) |
60
|
|
|
); |
61
|
2 |
|
} |
62
|
|
|
) |
63
|
|
|
) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
2 |
View Code Duplication |
public function delete(FrameChannel $channel, Deletion $command): Frame |
|
|
|
|
68
|
|
|
{ |
69
|
2 |
|
return new Frame( |
70
|
2 |
|
Type::method(), |
71
|
2 |
|
$channel, |
72
|
2 |
|
Methods::get('exchange.delete'), |
73
|
2 |
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
74
|
2 |
|
new ShortString(new Str($command->name())), |
75
|
2 |
|
new Bits( |
76
|
2 |
|
$command->onlyIfUnused(), |
77
|
2 |
|
!$command->shouldWait() |
78
|
|
|
) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|