Skip to content

Commit 12de1d9

Browse files
authored
Merge pull request #320 from patchlevel/remove-subscriber-util-getting-started
Remove deprecated `SubscriberUtil` from the getting started docs
2 parents 6f4ee05 + 9f3217d commit 12de1d9

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

docs/pages/getting_started.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ use Patchlevel\EventSourcing\Attribute\Projector;
189189
use Patchlevel\EventSourcing\Attribute\Setup;
190190
use Patchlevel\EventSourcing\Attribute\Subscribe;
191191
use Patchlevel\EventSourcing\Attribute\Teardown;
192-
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil;
192+
193+
use function sprintf;
193194

194195
/**
195196
* @psalm-type GuestData = array{
@@ -199,10 +200,10 @@ use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil;
199200
* check_out_date: string|null
200201
* }
201202
*/
202-
#[Projector('guests')]
203+
#[Projector(self::SUBSCRIBER_ID)]
203204
final class GuestProjection
204205
{
205-
use SubscriberUtil;
206+
private const SUBSCRIBER_ID = 'guests';
206207

207208
public function __construct(
208209
private Connection $db,
@@ -214,7 +215,7 @@ final class GuestProjection
214215
{
215216
return $this->db->createQueryBuilder()
216217
->select('*')
217-
->from($this->table())
218+
->from(self::SUBSCRIBER_ID)
218219
->where('hotel_id = :hotel_id')
219220
->setParameter('hotel_id', $hotelId->toString())
220221
->fetchAllAssociative();
@@ -226,7 +227,7 @@ final class GuestProjection
226227
DateTimeImmutable $recordedOn,
227228
): void {
228229
$this->db->insert(
229-
$this->table(),
230+
self::SUBSCRIBER_ID,
230231
[
231232
'hotel_id' => $event->hotelId->toString(),
232233
'guest_name' => $event->guestName,
@@ -242,7 +243,7 @@ final class GuestProjection
242243
DateTimeImmutable $recordedOn,
243244
): void {
244245
$this->db->update(
245-
$this->table(),
246+
self::SUBSCRIBER_ID,
246247
[
247248
'check_out_date' => $recordedOn->format('Y-m-d H:i:s'),
248249
],
@@ -257,25 +258,21 @@ final class GuestProjection
257258
#[Setup]
258259
public function create(): void
259260
{
260-
$this->db->executeStatement(
261-
"CREATE TABLE {$this->table()} (
261+
$this->db->executeStatement(sprintf(
262+
'CREATE TABLE %s (
262263
hotel_id VARCHAR(36) NOT NULL,
263264
guest_name VARCHAR(255) NOT NULL,
264265
check_in_date TIMESTAMP NOT NULL,
265266
check_out_date TIMESTAMP NULL
266-
);",
267-
);
267+
);',
268+
self::SUBSCRIBER_ID,
269+
));
268270
}
269271

270272
#[Teardown]
271273
public function drop(): void
272274
{
273-
$this->db->executeStatement("DROP TABLE IF EXISTS {$this->table()};");
274-
}
275-
276-
private function table(): string
277-
{
278-
return 'projection_' . $this->subscriberId();
275+
$this->db->executeStatement(sprintf('DROP TABLE IF EXISTS %s;', self::SUBSCRIBER_ID));
279276
}
280277
}
281278
```

0 commit comments

Comments
 (0)