1
|
|
|
<?php |
2
|
|
|
namespace PSB\Persistence\Doctrine1\Outbox; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use PSB\Core\Feature\Feature; |
6
|
|
|
use PSB\Core\KnownSettingsEnum; |
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
|
|
|
use PSB\Persistence\Doctrine1\Doctrine1KnownSettingsEnum; |
13
|
|
|
use PSB\Persistence\Doctrine1\LogicalConnection; |
14
|
|
|
use PSB\Persistence\Doctrine1\LogicalConnectionFactory; |
15
|
|
|
use PSB\Persistence\Doctrine1\Outbox\SchemaProvider\OutboxEndpointSchemaProvider; |
16
|
|
|
use PSB\Persistence\Doctrine1\Outbox\SchemaProvider\OutboxMessageSchemaProvider; |
17
|
|
|
|
18
|
|
|
class Doctrine1OutboxPersistenceFeature extends Feature |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Method will always be executed and should be used to determine whether to enable or disable the feature, |
23
|
|
|
* configure default settings, configure dependencies, configure prerequisites and register startup tasks. |
24
|
|
|
*/ |
25
|
1 |
|
public function describe() |
26
|
|
|
{ |
27
|
1 |
|
$this->dependsOn(OutboxFeature::class); |
28
|
1 |
|
$this->registerDefault( |
29
|
|
|
function (Settings $settings) { |
30
|
1 |
|
$settings->setDefault(Doctrine1KnownSettingsEnum::OUTBOX_MESSAGES_TABLE_NAME, 'psb_outbox_messages'); |
31
|
1 |
|
$settings->setDefault(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINTS_TABLE_NAME, 'psb_outbox_endpoints'); |
32
|
1 |
|
} |
33
|
1 |
|
); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Method is called if all defined conditions are met and the feature is marked as enabled. |
38
|
|
|
* Use this method to configure and initialize all required components for the feature like |
39
|
|
|
* the steps in the pipeline or the instances/factories in the container. |
40
|
|
|
* |
41
|
|
|
* @param Settings $settings |
42
|
|
|
* @param BuilderInterface $builder |
43
|
|
|
* @param PipelineModifications $pipelineModifications |
44
|
|
|
*/ |
45
|
1 |
|
public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications) |
46
|
|
|
{ |
47
|
1 |
|
$builder->defineSingleton(LogicalConnection::class, new LogicalConnectionFactory($settings)); |
48
|
|
|
|
49
|
1 |
|
$builder->defineSingleton( |
50
|
1 |
|
OutboxPersister::class, |
51
|
|
|
function () use ($builder, $settings) { |
52
|
|
|
return new OutboxPersister( |
53
|
|
|
$builder->build(LogicalConnection::class), |
54
|
|
|
$settings->get(Doctrine1KnownSettingsEnum::OUTBOX_MESSAGES_TABLE_NAME), |
55
|
|
|
$settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINTS_TABLE_NAME) |
56
|
|
|
); |
57
|
|
|
} |
58
|
1 |
|
); |
59
|
|
|
|
60
|
1 |
|
$builder->defineSingleton( |
61
|
1 |
|
OutboxStorageInterface::class, |
62
|
|
|
function () use ($builder, $settings) { |
63
|
|
|
return new Doctrine1OutboxStorage( |
64
|
|
|
$builder->build(OutboxPersister::class), |
65
|
|
|
new OutboxMessageConverter(), |
66
|
|
|
$settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINT_ID) |
67
|
|
|
); |
68
|
|
|
} |
69
|
1 |
|
); |
70
|
|
|
|
71
|
1 |
|
$this->registerStartupTask( |
72
|
|
|
function () use ($builder, $settings) { |
73
|
|
|
return new EndpointIdLoaderFeatureStartupTask( |
74
|
|
|
$builder->build(OutboxPersister::class), |
75
|
|
|
$settings, |
76
|
|
|
$settings->get(KnownSettingsEnum::ENDPOINT_NAME) |
77
|
|
|
); |
78
|
|
|
} |
79
|
1 |
|
); |
80
|
|
|
|
81
|
1 |
|
$this->registerStartupTask( |
82
|
|
|
function () use ($builder, $settings) { |
83
|
|
|
return new OutboxCleanerFeatureStartupTask( |
84
|
|
|
$builder->build(OutboxPersister::class), |
85
|
|
|
new \DateTime('now', new \DateTimeZone('UTC')), |
86
|
|
|
$settings->tryGet(KnownSettingsEnum::DAYS_TO_KEEP_DEDUPLICATION_DATA) |
87
|
|
|
); |
88
|
|
|
} |
89
|
1 |
|
); |
90
|
|
|
|
91
|
1 |
|
$this->registerInstallTask( |
92
|
|
|
function () use ($builder, $settings) { |
93
|
|
|
return new OutboxTablesCreatorFeatureInstallTask( |
94
|
|
|
$builder->build(LogicalConnection::class), |
95
|
|
|
new OutboxEndpointSchemaProvider(), |
96
|
|
|
new OutboxMessageSchemaProvider(), |
97
|
|
|
$settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINTS_TABLE_NAME), |
98
|
|
|
$settings->get(Doctrine1KnownSettingsEnum::OUTBOX_MESSAGES_TABLE_NAME) |
99
|
|
|
); |
100
|
|
|
} |
101
|
1 |
|
); |
102
|
1 |
|
} |
103
|
|
|
} |
104
|
|
|
|