Skip to content

Commit 133322d

Browse files
committed
format docs
1 parent 8258f60 commit 133322d

1 file changed

Lines changed: 31 additions & 38 deletions

File tree

docs/pages/subscription.md

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ final class DoStuffSubscriber
293293
}
294294
}
295295
```
296-
297296
##### Custom Resolvers
298297

299298
You can provide your own argument resolvers by implementing the `ArgumentResolver` interface.
@@ -309,7 +308,6 @@ This is especially helpful for projectors, as they can create the necessary stru
309308
use Doctrine\DBAL\Connection;
310309
use Patchlevel\EventSourcing\Attribute\Projector;
311310
use Patchlevel\EventSourcing\Attribute\Setup;
312-
use Patchlevel\EventSourcing\Attribute\Teardown;
313311

314312
#[Projector(self::TABLE)]
315313
final class ProfileProjector
@@ -352,7 +350,6 @@ For this there is the attributes `Teardown`.
352350
```php
353351
use Doctrine\DBAL\Connection;
354352
use Patchlevel\EventSourcing\Attribute\Projector;
355-
use Patchlevel\EventSourcing\Attribute\Setup;
356353
use Patchlevel\EventSourcing\Attribute\Teardown;
357354

358355
#[Projector(self::TABLE)]
@@ -361,7 +358,7 @@ final class ProfileProjector
361358
private const TABLE = 'profile_v1';
362359

363360
private Connection $connection;
364-
361+
365362
#[Teardown]
366363
public function drop(): void
367364
{
@@ -374,7 +371,7 @@ final class ProfileProjector
374371
MySQL and MariaDB don't support transactions for DDL statements.
375372
So you must use a different database connection in your projectors,
376373
otherwise you will get an error when the subscription tries to create the table.
377-
374+
378375
!!! warning
379376

380377
A teardown can only be performed for a subscription if the code for the subscriber with that subscriber ID still exists.
@@ -383,20 +380,19 @@ final class ProfileProjector
383380
!!! note
384381

385382
You can not mix the `cleanup` method with the `teardown` method.
386-
383+
387384
### Cleanup
388385

389386
Alternativ, you can use a `cleanup` method for cleanup tasks.
390387
Unlike Teardown, this method is called when the subscription is created.
391388
The tasks are then saved in the Subscription Store.
392-
When removing the subscription, the subscriber is not necessary anymore,
389+
When removing the subscription, the subscriber is not necessary anymore,
393390
as the cleanup can be performed using the tasks in the store and an associated external handler.
394391

395392
```php
396393
use Doctrine\DBAL\Connection;
397394
use Patchlevel\EventSourcing\Attribute\Cleanup;
398395
use Patchlevel\EventSourcing\Attribute\Projector;
399-
use Patchlevel\EventSourcing\Attribute\Setup;
400396
use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DropIndexTask;
401397

402398
#[Projector(self::TABLE)]
@@ -405,21 +401,18 @@ final class ProfileProjector
405401
private const TABLE = 'profile_v1';
406402

407403
private Connection $connection;
408-
404+
409405
#[Cleanup]
410406
public function drop(): array
411407
{
412-
return [
413-
new DropIndexTask(self::TABLE)
414-
];
408+
return [new DropIndexTask(self::TABLE)];
415409
}
416410
}
417411
```
418-
419412
!!! note
420413

421414
You can not mix the `cleanup` method with the `teardown` method.
422-
415+
423416
#### Dbal Cleanup Tasks
424417

425418
Default, we provide the following cleanup tasks for `doctrine/dbal`:
@@ -433,7 +426,7 @@ Default, we provide the following cleanup tasks for `doctrine/dbal`:
433426

434427
You can create your own cleanup tasks and handler.
435428
For more information, see [Cleanup Handler](#cleanup-handler).
436-
429+
437430
### On Failed
438431

439432
The subscription engine has a [retry strategy](#retry-strategy) to retry subscriptions that have an error.
@@ -1008,51 +1001,55 @@ $retryStrategyRepository = new RetryStrategyRepository([
10081001
!!! tip
10091002

10101003
You can change the default retry strategy by define the name in the constructor as second parameter.
1011-
1004+
10121005
### Cleanup Handler
10131006

10141007
You can also create your own cleanup tasks with associated handlers.
10151008
First, create a task class that has all necessary information for the task.
10161009
In our example, we create a task that deletes a collection from MongoDB.
10171010

10181011
```php
1019-
final class DropCollection {
1012+
final class DropCollection
1013+
{
10201014
public function __construct(
1021-
public readonly string $collectionName
1022-
) {}
1015+
public readonly string $collectionName,
1016+
) {
1017+
}
10231018
}
10241019
```
1025-
10261020
!!! warning
10271021

10281022
The task class must be serializable. It will be stored in the subscription store.
1029-
1030-
The next step is to create a handler for the task.
1023+
1024+
The next step is to create a handler for the task.
10311025
The handler must implement the `CleanupHandler` interface.
10321026

10331027
```php
10341028
use MongoDb\Database;
10351029
use Patchlevel\EventSourcing\Subscription\Cleanup\CleanupHandler;
10361030

1037-
final class MongodbCleanupHandler implements CleanupHandler {
1031+
final class MongodbCleanupHandler implements CleanupHandler
1032+
{
10381033
public function __construct(
1039-
private readonly Database $database
1040-
) {}
1041-
1034+
private readonly Database $database,
1035+
) {
1036+
}
1037+
10421038
public function __invoke(object $task): void
10431039
{
1044-
if ($task instanceof DropCollection) {
1045-
$this->database->dropCollection($task->collectionName);
1040+
if (!($task instanceof DropCollection)) {
1041+
return;
10461042
}
1043+
1044+
$this->database->dropCollection($task->collectionName);
10471045
}
1048-
1046+
10491047
public function supports(object $task): bool
10501048
{
10511049
return $task instanceof DropCollection;
10521050
}
10531051
}
10541052
```
1055-
10561053
Lastly, we have to add the new handler to `DefaultCleaner`,
10571054
which is responsible for cleaning up subscriptions.
10581055

@@ -1064,11 +1061,10 @@ $cleaner = new DefaultCleaner([
10641061
new MongodbCleanupHandler($mongodbDatabase),
10651062
]);
10661063
```
1067-
10681064
!!! warning
10691065

10701066
You need to pass the Cleaner to the Subscription Engine.
1071-
1067+
10721068
### Subscriber Accessor
10731069

10741070
The subscriber accessor repository is responsible for providing the subscribers to the subscription engine.
@@ -1088,7 +1084,6 @@ $subscriberAccessorRepository = new MetadataSubscriberAccessorRepository([
10881084
$subscriber3,
10891085
]);
10901086
```
1091-
10921087
### Subscription Engine
10931088

10941089
Now we can create the subscription engine and plug together the necessary services.
@@ -1098,13 +1093,13 @@ Finally, if we want to use the cleanup feature, we need to pass the cleanup hand
10981093

10991094
```php
11001095
use Doctrine\DBAL\Connection;
1096+
use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupHandler;
1097+
use Patchlevel\EventSourcing\Subscription\Cleanup\DefaultCleaner;
11011098
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
11021099
use Patchlevel\EventSourcing\Subscription\Engine\MessageLoader;
11031100
use Patchlevel\EventSourcing\Subscription\RetryStrategy\RetryStrategyRepository;
11041101
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
11051102
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
1106-
use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupHandler;
1107-
use Patchlevel\EventSourcing\Subscription\Cleanup\DefaultCleaner;
11081103

11091104
/**
11101105
* @var MessageLoader $messageLoader
@@ -1120,9 +1115,7 @@ $subscriptionEngine = new DefaultSubscriptionEngine(
11201115
$subscriberAccessorRepository,
11211116
$retryStrategyRepository, // optional, if not set the default retry strategy is used
11221117
$logger, // optional
1123-
new DefaultCleaner([
1124-
new DbalCleanupHandler($projectionConnection)
1125-
]), // optional but required if you want to use the cleanup feature
1118+
new DefaultCleaner([new DbalCleanupHandler($projectionConnection)]), // optional but required if you want to use the cleanup feature
11261119
);
11271120
```
11281121
### Catch up Subscription Engine

0 commit comments

Comments
 (0)