Skip to content

Commit 524f2a5

Browse files
committed
docs: update upgrade guide and message docs for 4.0 breaking changes
Document the breaking changes from the merged 4.0 PRs that were missing from the upgrade guide: - stream refactor (#847): Store\Stream interface replaced by the concrete Message\Stream class, removed store-specific stream implementations, Message\Pipe removed in favor of Stream::transform() - removed deprecated SubscriberHelper and SubscriberUtil (#805) - removed SubscriberAccessor / RealSubscriberAccessor interfaces and deprecated accessor methods, removed AggregateIdArgumentResolver (#756) - ArgumentMetadata now carries a symfony/type-info Type (#814) Also update the message docs Pipe section to use the new Stream API.
1 parent 543bd2c commit 524f2a5

2 files changed

Lines changed: 96 additions & 6 deletions

File tree

docs/UPGRADE-4.0.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,47 @@ Further changes:
140140
* `ProcessedResult` now extends `Result`, so the `execute` method always returns a `Result`. The `Boot` and `Run` commands return a `ProcessedResult`.
141141
* The `DefaultSubscriptionEngine` accepts an optional `EventDispatcherInterface` as last constructor argument to hook into the engine with own listeners.
142142

143+
### SubscriberHelper and SubscriberUtil
144+
145+
The deprecated `Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper`
146+
and the `Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil` trait have been removed.
147+
148+
If you need the subscriber id, read it from the metadata instead:
149+
150+
```php
151+
use Patchlevel\EventSourcing\Metadata\Subscriber\AttributeSubscriberMetadataFactory;
152+
153+
$metadata = (new AttributeSubscriberMetadataFactory())->metadata($subscriber::class);
154+
$subscriberId = $metadata->id;
155+
```
156+
157+
### SubscriberAccessor and RealSubscriberAccessor
158+
159+
The `Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberAccessor` and
160+
`Patchlevel\EventSourcing\Subscription\Subscriber\RealSubscriberAccessor` interfaces have been removed.
161+
Use `Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessor` directly.
162+
163+
Accordingly, `SubscriberAccessorRepository::get()` now returns a `MetadataSubscriberAccessor|null`
164+
instead of a `SubscriberAccessor|null`.
165+
166+
The deprecated methods `id()`, `group()` and `runMode()` on `MetadataSubscriberAccessor` have been removed.
167+
Use `->metadata()->id`, `->metadata()->group` and `->metadata()->runMode` instead.
168+
169+
### AggregateIdArgumentResolver
170+
171+
The deprecated `Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\AggregateIdArgumentResolver`
172+
has been removed. Automatically resolving the aggregate id in a stream store is not possible.
173+
Add the aggregate id to your events instead.
174+
175+
### ArgumentMetadata
176+
177+
The subscriber argument resolver now uses `symfony/type-info` to describe argument types.
178+
179+
`Patchlevel\EventSourcing\Metadata\Subscriber\ArgumentMetadata` no longer carries a `string $type`
180+
and a `bool $allowsNull` property. Instead it now has a single `Symfony\Component\TypeInfo\Type $type` property.
181+
182+
If you implemented a custom `ArgumentResolver`, adjust it to read the type from the new `Type` object.
183+
143184
## Store
144185

145186
### StreamStore
@@ -160,6 +201,49 @@ And all the associated classes:
160201

161202
`StreamReadOnlyStore` was been merged in `ReadOnlyStore`.
162203

204+
## Stream
205+
206+
The stream handling has been reworked. Previously the `Stream` was an interface that every store had to
207+
implement on its own (`ArrayStream`, `StreamDoctrineDbalStoreStream`, `TaggableDoctrineDbalStoreStream`,
208+
`GeneratorStream`, ...). Now there is a single generic implementation that you can reuse.
209+
210+
### Stream interface
211+
212+
The `Patchlevel\EventSourcing\Store\Stream` interface has been removed and replaced by the concrete final
213+
class `Patchlevel\EventSourcing\Message\Stream`.
214+
215+
All stores now return a `Patchlevel\EventSourcing\Message\Stream` from their `load()` method.
216+
The following store specific stream implementations have been removed:
217+
218+
* `Patchlevel\EventSourcing\Store\ArrayStream`
219+
* `Patchlevel\EventSourcing\Store\StreamDoctrineDbalStoreStream`
220+
* `Patchlevel\EventSourcing\Store\TaggableDoctrineDbalStoreStream`
221+
* `Patchlevel\EventSourcing\Subscription\Engine\GeneratorStream`
222+
223+
The new `Stream` class implements `Iterator` and accepts any `iterable<Message>` in its constructor.
224+
The `index()`, `position()`, `end()` and `close()` methods remain available.
225+
In addition there are now the helper methods `toList()`, `toArray()`, `transform()` and `chunk()`.
226+
227+
### Pipe
228+
229+
`Patchlevel\EventSourcing\Message\Pipe` has been removed. Use `Stream::transform()` instead.
230+
231+
before:
232+
233+
```php
234+
use Patchlevel\EventSourcing\Message\Pipe;
235+
236+
$messages = (new Pipe($messages, $translator))->toArray();
237+
```
238+
239+
after:
240+
241+
```php
242+
use Patchlevel\EventSourcing\Message\Stream;
243+
244+
$messages = (new Stream($messages))->transform($translator)->toList();
245+
```
246+
163247
## Message
164248

165249
### AggregateHeader

docs/message.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,33 @@ use Patchlevel\EventSourcing\Message\Message;
9797
/** @var Message $message */
9898
$message->header(ApplicationHeader::class);
9999
```
100-
## Pipe
100+
## Stream
101101

102-
The `Pipe` is a construct that allows you to chain multiple translators.
102+
A `Stream` wraps an iterable of messages and allows you to chain multiple translators with `transform`.
103103
This can be used to manipulate, filter or expand messages or events.
104104
This can be used for anti-corruption layers, data migration, or to fix errors in the event stream.
105105

106106
```php
107-
use Patchlevel\EventSourcing\Message\Pipe;
107+
use Patchlevel\EventSourcing\Message\Stream;
108108
use Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator;
109109
use Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator;
110110

111-
$messages = new Pipe(
112-
$messages,
111+
$stream = (new Stream($messages))->transform(
113112
new ExcludeEventTranslator([ProfileCreated::class]),
114113
new RecalculatePlayheadTranslator(),
115114
);
116115

117-
foreach ($messages as $message) {
116+
foreach ($stream as $message) {
118117
// do something with the message
119118
}
120119
```
120+
121+
:::tip
122+
A `Stream` is also what every store returns from its `load` method, so you can apply the same
123+
transformations to the messages you read from the store. Besides iterating, a `Stream` offers
124+
`toList()`, `toArray()` and `chunk()` to consume the messages.
125+
:::
126+
121127
## Translator
122128

123129
Translator can be used to manipulate, filter or expand messages or events.

0 commit comments

Comments
 (0)