|
1
|
|
|
<?php |
|
2
|
|
|
namespace PSB\Core\Persistence\InMemory\Outbox; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use PSB\Core\Feature\Feature; |
|
6
|
|
|
use PSB\Core\Feature\FeatureSettingsExtensions; |
|
7
|
|
|
use PSB\Core\ObjectBuilder\BuilderInterface; |
|
8
|
|
|
use PSB\Core\Outbox\OutboxFeature; |
|
9
|
|
|
use PSB\Core\Outbox\OutboxStorageInterface; |
|
10
|
|
|
use PSB\Core\Pipeline\PipelineModifications; |
|
11
|
|
|
use PSB\Core\Util\Settings; |
|
12
|
|
|
|
|
13
|
|
|
class InMemoryOutboxPersistenceFeature extends Feature |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Method will always be executed and should be used to determine whether to enable or disable the feature, |
|
18
|
|
|
* configure default settings, configure dependencies, configure prerequisites and register startup tasks. |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function describe() |
|
21
|
|
|
{ |
|
22
|
1 |
|
$this->dependsOn(OutboxFeature::class); |
|
23
|
1 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Method is called if all defined conditions are met and the feature is marked as enabled. |
|
27
|
|
|
* Use this method to configure and initialize all required components for the feature like |
|
28
|
|
|
* the steps in the pipeline or the instances/factories in the container. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Settings $settings |
|
31
|
|
|
* @param BuilderInterface $builder |
|
32
|
|
|
* @param PipelineModifications $pipelineModifications |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications) |
|
35
|
|
|
{ |
|
36
|
2 |
|
$outboxEnabled = FeatureSettingsExtensions::isFeatureActive(OutboxFeature::class, $settings); |
|
37
|
|
|
|
|
38
|
2 |
|
if ($outboxEnabled) { |
|
39
|
1 |
|
$builder->defineSingleton( |
|
40
|
1 |
|
OutboxStorageInterface::class, |
|
41
|
|
|
function () use ($builder, $settings) { |
|
42
|
|
|
return new InMemoryOutboxStorage(); |
|
43
|
1 |
|
} |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
2 |
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|