|
1
|
|
|
<?php |
|
2
|
|
|
namespace PSB\Core\Transport; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use PSB\Core\Feature\Feature; |
|
6
|
|
|
use PSB\Core\KnownSettingsEnum; |
|
7
|
|
|
use PSB\Core\ObjectBuilder\BuilderInterface; |
|
8
|
|
|
use PSB\Core\Pipeline\PipelineModifications; |
|
9
|
|
|
use PSB\Core\Util\Settings; |
|
10
|
|
|
|
|
11
|
|
|
class ReceivingFeature extends Feature |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Method will always be executed and should be used to determine whether to enable or disable the feature, |
|
16
|
|
|
* configure default settings, configure dependencies, configure prerequisites and register startup tasks. |
|
17
|
|
|
*/ |
|
18
|
1 |
|
public function describe() |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this->enableByDefault(); |
|
21
|
1 |
|
$this->dependsOn(TransportFeature::class); |
|
22
|
1 |
|
$this->registerPrerequisite( |
|
23
|
|
|
function (Settings $settings) { |
|
24
|
|
|
return !$settings->tryGet(KnownSettingsEnum::SEND_ONLY); |
|
25
|
1 |
|
}, |
|
26
|
1 |
|
"Endpoint is configured as send only." |
|
27
|
|
|
); |
|
28
|
1 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Method is called if all defined conditions are met and the feature is marked as enabled. |
|
32
|
|
|
* Use this method to configure and initialize all required components for the feature like |
|
33
|
|
|
* the steps in the pipeline or the instances/factories in the container. |
|
34
|
|
|
* |
|
35
|
|
|
* @param Settings $settings |
|
36
|
|
|
* @param BuilderInterface $builder |
|
37
|
|
|
* @param PipelineModifications $pipelineModifications |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications) |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var QueueBindings $queueBindings */ |
|
42
|
1 |
|
$queueBindings = $settings->get(QueueBindings::class); |
|
43
|
1 |
|
$queueBindings->bindReceiving($settings->get(KnownSettingsEnum::LOCAL_ADDRESS)); |
|
44
|
|
|
|
|
45
|
|
|
/** @var InboundTransport $inboundTransport */ |
|
46
|
1 |
|
$inboundTransport = $settings->get(InboundTransport::class); |
|
47
|
1 |
|
$receiveInfrastructure = $inboundTransport->configure($settings); |
|
48
|
|
|
|
|
49
|
1 |
|
$builder->defineSingleton(MessagePusherInterface::class, $receiveInfrastructure->getMessagePusherFactory()); |
|
50
|
1 |
|
$builder->defineSingleton(QueueCreatorInterface::class, $receiveInfrastructure->getQueueCreatorFactory()); |
|
51
|
|
|
|
|
52
|
1 |
|
$this->registerInstallTask( |
|
53
|
|
|
function () use ($builder, $settings) { |
|
54
|
|
|
return new QueueCreatorFeatureInstallTask($builder->build(QueueCreatorInterface::class), $settings); |
|
55
|
1 |
|
} |
|
56
|
|
|
); |
|
57
|
1 |
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|