Skip to content

Commit 1646ad0

Browse files
committed
do not use deprecated features in getting started
1 parent d299508 commit 1646ad0

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

docs/pages/getting_started.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ final class HotelCreated
2626
A guest can check in by `name`:
2727

2828
```php
29+
use Patchlevel\EventSourcing\Aggregate\Uuid;
2930
use Patchlevel\EventSourcing\Attribute\Event;
3031

3132
#[Event('hotel.guest_checked_in')]
3233
final class GuestIsCheckedIn
3334
{
3435
public function __construct(
36+
public readonly Uuid $hotelId,
3537
public readonly string $guestName,
3638
) {
3739
}
@@ -40,12 +42,14 @@ final class GuestIsCheckedIn
4042
And also check out again:
4143

4244
```php
45+
use Patchlevel\EventSourcing\Aggregate\Uuid;
4346
use Patchlevel\EventSourcing\Attribute\Event;
4447

4548
#[Event('hotel.guest_checked_out')]
4649
final class GuestIsCheckedOut
4750
{
4851
public function __construct(
52+
public readonly Uuid $hotelId,
4953
public readonly string $guestName,
5054
) {
5155
}
@@ -65,7 +69,6 @@ Last but not least, we need the associated apply methods to change the state.
6569

6670
```php
6771
use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
68-
use Patchlevel\EventSourcing\Aggregate\Uuid;
6972
use Patchlevel\EventSourcing\Attribute\Aggregate;
7073
use Patchlevel\EventSourcing\Attribute\Apply;
7174
use Patchlevel\EventSourcing\Attribute\Id;
@@ -105,7 +108,7 @@ final class Hotel extends BasicAggregateRoot
105108
throw new GuestHasAlreadyCheckedIn($guestName);
106109
}
107110

108-
$this->recordThat(new GuestIsCheckedIn($guestName));
111+
$this->recordThat(new GuestIsCheckedIn($this->id, $guestName));
109112
}
110113

111114
public function checkOut(string $guestName): void
@@ -114,7 +117,7 @@ final class Hotel extends BasicAggregateRoot
114117
throw new IsNotAGuest($guestName);
115118
}
116119

117-
$this->recordThat(new GuestIsCheckedOut($guestName));
120+
$this->recordThat(new GuestIsCheckedOut($this->id, $guestName));
118121
}
119122

120123
#[Apply]
@@ -179,33 +182,33 @@ final class HotelProjector
179182
}
180183

181184
#[Subscribe(HotelCreated::class)]
182-
public function handleHotelCreated(HotelCreated $event, Uuid $aggregateId): void
185+
public function handleHotelCreated(HotelCreated $event): void
183186
{
184187
$this->db->insert(
185188
$this->table(),
186189
[
187-
'id' => $aggregateId->toString(),
190+
'id' => $event->hotelId->toString(),
188191
'name' => $event->hotelName,
189192
'guests' => 0,
190193
],
191194
);
192195
}
193196

194197
#[Subscribe(GuestIsCheckedIn::class)]
195-
public function handleGuestIsCheckedIn(Uuid $aggregateId): void
198+
public function handleGuestIsCheckedIn(GuestIsCheckedIn $event): void
196199
{
197200
$this->db->executeStatement(
198201
"UPDATE {$this->table()} SET guests = guests + 1 WHERE id = ?;",
199-
[$aggregateId->toString()],
202+
[$event->hotelId->toString()],
200203
);
201204
}
202205

203206
#[Subscribe(GuestIsCheckedOut::class)]
204-
public function handleGuestIsCheckedOut(Uuid $aggregateId): void
207+
public function handleGuestIsCheckedOut(GuestIsCheckedOut $event): void
205208
{
206209
$this->db->executeStatement(
207210
"UPDATE {$this->table()} SET guests = guests - 1 WHERE id = ?;",
208-
[$aggregateId->toString()],
211+
[$event->hotelId->toString()],
209212
);
210213
}
211214

0 commit comments

Comments
 (0)