1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP; |
5
|
|
|
|
6
|
|
|
use Innmind\Socket\Internet\Transport as Socket; |
7
|
|
|
use Innmind\Url\UrlInterface; |
8
|
|
|
use Innmind\TimeContinuum\{ |
9
|
|
|
TimeContinuumInterface, |
10
|
|
|
ElapsedPeriod, |
11
|
|
|
}; |
12
|
|
|
use Innmind\CLI\Command as CLICommand; |
13
|
|
|
use Innmind\OperatingSystem\{ |
14
|
|
|
CurrentProcess, |
15
|
|
|
CurrentProcess\Signals, |
16
|
|
|
Remote, |
17
|
|
|
}; |
18
|
|
|
use Innmind\Immutable\{ |
19
|
|
|
SetInterface, |
20
|
|
|
MapInterface, |
21
|
|
|
}; |
22
|
|
|
use Psr\Log\LoggerInterface; |
23
|
|
|
|
24
|
|
|
function bootstrap(LoggerInterface $logger = null): array |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
'client' => [ |
28
|
|
|
'basic' => static function( |
29
|
|
|
Socket $transport, |
30
|
|
|
UrlInterface $server, |
31
|
|
|
ElapsedPeriod $timeout, |
32
|
|
|
TimeContinuumInterface $clock, |
33
|
|
|
CurrentProcess $process, |
34
|
|
|
Remote $remote |
35
|
|
|
) use ( |
36
|
2 |
|
$logger |
37
|
|
|
): Client { |
38
|
2 |
|
$connection = new Transport\Connection\Lazy( |
39
|
2 |
|
$transport, |
40
|
1 |
|
$server, |
41
|
2 |
|
new Transport\Protocol\v091\Protocol( |
42
|
2 |
|
new Transport\Protocol\ArgumentTranslator\ValueTranslator |
43
|
|
|
), |
44
|
1 |
|
$timeout, |
45
|
1 |
|
$clock, |
46
|
1 |
|
$remote |
47
|
|
|
); |
48
|
|
|
|
49
|
2 |
|
if ($logger instanceof LoggerInterface) { |
50
|
2 |
|
$connection = new Transport\Connection\Logger($connection, $logger); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
return new Client\Client($connection, $process); |
54
|
2 |
|
}, |
55
|
|
|
'fluent' => static function(Client $client): Client { |
56
|
2 |
|
return new Client\Fluent($client); |
57
|
2 |
|
}, |
58
|
|
|
'logger' => static function(Client $client) use ($logger): Client { |
59
|
2 |
|
return new Client\Logger($client, $logger); |
60
|
2 |
|
}, |
61
|
|
|
'signal_aware' => static function(Client $client, Signals $signals): Client { |
62
|
2 |
|
return new Client\SignalAware($client, $signals); |
63
|
2 |
|
}, |
64
|
|
|
'auto_declare' => static function(SetInterface $exchanges, SetInterface $queues, SetInterface $bindings): callable { |
65
|
|
|
return static function(Client $client) use ($exchanges, $queues, $bindings): Client { |
66
|
2 |
|
return new Client\AutoDeclare($client, $exchanges, $queues, $bindings); |
67
|
2 |
|
}; |
68
|
2 |
|
}, |
69
|
|
|
], |
70
|
|
|
'command' => [ |
71
|
|
|
'purge' => static function(Client $client): CLICommand { |
72
|
2 |
|
return new Command\Purge($client); |
73
|
2 |
|
}, |
74
|
|
|
'get' => static function(MapInterface $consumers): callable { |
75
|
|
|
return static function(Client $client) use ($consumers): CLICommand { |
76
|
2 |
|
return new Command\Get($client, new Consumers($consumers)); |
77
|
2 |
|
}; |
78
|
2 |
|
}, |
79
|
|
|
'consume' => static function(MapInterface $consumers): callable { |
80
|
|
|
return static function(Client $client) use ($consumers): CLICommand { |
81
|
2 |
|
return new Command\Consume($client, new Consumers($consumers)); |
82
|
2 |
|
}; |
83
|
2 |
|
}, |
84
|
|
|
], |
85
|
|
|
'producers' => static function(SetInterface $exchanges): callable { |
86
|
|
|
return static function(Client $client) use ($exchanges): Producers { |
87
|
2 |
|
return Producers::fromDeclarations($client, ...$exchanges); |
88
|
2 |
|
}; |
89
|
2 |
|
}, |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|