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