Advanced Aggregate creation
DDD PHP
Create an Aggregate by another Aggregate
Create a State-based Aggregate
#[Aggregate]
final class Calendar
{
/** @var array<string> */
private array $meetings = [];
public function __construct(#[Identifier] public string $calendarId)
{
}
#[CommandHandler]
public function scheduleMeeting(ScheduleMeeting $command): Meeting
{
// checking business rules
$this->meetings[] = $command->meetingId;
return new Meeting($command->meetingId);
}
}
#[Aggregate]
final class Meeting
{
public function __construct(#[Identifier] public string $meetingId)
{
}
}Create an Event Sourcing Aggregate
Events handling
Persisting a state change
Last updated
Was this helpful?