This commit is contained in:
Martin Slachta
2026-06-11 19:03:29 +02:00
commit 0d829845c4
150 changed files with 38582 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
interface RsvEventBusInterface {
public function dispatch(object $event): void;
public function listen(string $event_class, callable $listener): void;
}
class RsvWordPressEventBus implements RsvEventBusInterface {
public function dispatch(object $event): void {
do_action(get_class($event), $event);
}
public function listen(string $event_class, callable $listener): void {
add_action($event_class, $listener);
}
}
class RsvEventDispatcher {
private static ?RsvEventBusInterface $bus = null;
public static function init(RsvEventBusInterface $bus): void {
self::$bus = $bus;
}
private static function bus(): RsvEventBusInterface {
// Fall back to the WordPress bus if init() was never called, so a stray
// dispatch/listen during early bootstrap can't fatal on an uninitialised
// typed property.
return self::$bus ??= new RsvWordPressEventBus();
}
public static function dispatch(object $event): void {
self::bus()->dispatch($event);
}
public static function listen(string $event_class, callable $listener): void {
self::bus()->listen($event_class, $listener);
}
}
@@ -0,0 +1,17 @@
<?php
/**
* Dispatched when every element of a form submission reaches its terminal
* state — i.e. the form transitions from open to closed.
*
* $accepted is true when every timetable item was confirmed, false when at
* least one was refused. It is resolved at dispatch time so listeners never
* need a second database round-trip.
*/
final class RsvFormSubmitClosedEvent {
public function __construct(
public int $form_submit_id,
public int $reservation_id,
public bool $accepted
) {}
}
@@ -0,0 +1,11 @@
<?php
/**
* Dispatched when every timetable item of a reservation is confirmed, i.e. the
* whole reservation has been accepted.
*/
class RsvReservationConfirmedEvent {
public function __construct(
public int $reservation_id
) {}
}
@@ -0,0 +1,11 @@
<?php
/**
* Dispatched when a reservation is refused (at least one of its timetable items
* was rejected), so the whole reservation can no longer be confirmed.
*/
class RsvReservationRefusedEvent {
public function __construct(
public int $reservation_id
) {}
}
@@ -0,0 +1,7 @@
<?php
class RsvTimetableReservationAcceptedEvent {
public function __construct(
public int $reservation_id
) {}
}
@@ -0,0 +1,7 @@
<?php
class RsvTimetableReservationCreatedEvent {
public function __construct(
public RsvTimetableReservation $reservation
) {}
}
@@ -0,0 +1,15 @@
<?php
/**
* Dispatched when a single timetable reservation item requires maintainer
* confirmation. Carries everything the email module needs so it never has to
* reach back into the reservation services.
*/
class RsvTimetableReservationPendingEvent {
public function __construct(
public int $reservation_id,
public RsvTimetableReservation $reservation,
public string $code,
public string $maintainer_email
) {}
}
@@ -0,0 +1,7 @@
<?php
class RsvTimetableReservationRefusedEvent {
public function __construct(
public int $reservation_id
) {}
}