Announcement
in package
FinalYes
Announcement Entity Aggregate Root for Announcement domain
Table of Contents
Properties
- $decidedAt : DateTimeImmutable|null
- $decidedBy : int|null
- $status : AnnouncementStatus
- $text : string
- $title : string
- $validUntil : DateTimeImmutable
- $createdAt : DateTimeImmutable
- $events : array<string|int, mixed>
- $id : AnnouncementId|null
- $userId : int|null
Methods
- __construct() : mixed
- approve() : void
- Change status to approved
- clearDomainEvents() : void
- create() : self
- Creates a new announcement <br> Announcement is approved by default
- fromArray() : self
- Hydrate from database array
- getCreatedAt() : DateTimeImmutable
- getDomainEvents() : array<string|int, mixed>
- getId() : AnnouncementId|null
- getUserId() : int|null
- isValid() : bool
- Checks if an announcement is valid - Status must be APPROVED - Valid until date must be in the future
- proposeNew() : self
- Proposes a new announcement
- reject() : void
- Change status to rejected
- toArray() : array<string|int, mixed>
- Serialize to array (for database storage)
- update() : void
- Updates announcement data
- recordEvent() : void
Properties
$decidedAt
public
DateTimeImmutable|null
$decidedAt
= null
Hooks
public
DateTimeImmutable|null
get
public
set
$decidedBy
public
int|null
$decidedBy
= null
Hooks
public
int|null
get
public
set
$status
public
AnnouncementStatus
$status
= AnnouncementStatus::PENDING
Hooks
public
AnnouncementStatus
get
public
set
Parameters
- $value : AnnouncementStatus
$text
public
string
$text
Hooks
public
string
get
$title
public
string
$title
Hooks
public
string
get
$validUntil
public
DateTimeImmutable
$validUntil
Hooks
public
DateTimeImmutable
get
$createdAt read-only
private
DateTimeImmutable
$createdAt
$events
private
array<string|int, mixed>
$events
= []
$id read-only
private
AnnouncementId|null
$id
$userId read-only
private
int|null
$userId
Methods
__construct()
public
__construct(AnnouncementId|null $id, string $title, string $text, DateTimeImmutable $createdAt, DateTimeImmutable $validUntil, int|null $userId[, AnnouncementStatus $status = AnnouncementStatus::PENDING ][, DateTimeImmutable|null $decidedAt = null ][, int|null $decidedBy = null ]) : mixed
Parameters
- $id : AnnouncementId|null
- $title : string
- $text : string
- $createdAt : DateTimeImmutable
- $validUntil : DateTimeImmutable
- $userId : int|null
- $status : AnnouncementStatus = AnnouncementStatus::PENDING
- $decidedAt : DateTimeImmutable|null = null
- $decidedBy : int|null = null
approve()
Change status to approved
public
approve(int $decidedBy) : void
Parameters
- $decidedBy : int
clearDomainEvents()
public
clearDomainEvents() : void
create()
Creates a new announcement <br> Announcement is approved by default
public
static create(string $title, string $text, DateTimeImmutable $validUntil, int $userId) : self
Parameters
- $title : string
- $text : string
- $validUntil : DateTimeImmutable
- $userId : int
Return values
selffromArray()
Hydrate from database array
public
static fromArray(array<string|int, mixed> $data) : self
Parameters
- $data : array<string|int, mixed>
Return values
selfgetCreatedAt()
public
getCreatedAt() : DateTimeImmutable
Return values
DateTimeImmutablegetDomainEvents()
public
getDomainEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>getId()
public
getId() : AnnouncementId|null
Return values
AnnouncementId|nullgetUserId()
public
getUserId() : int|null
Return values
int|nullisValid()
Checks if an announcement is valid - Status must be APPROVED - Valid until date must be in the future
public
isValid() : bool
Return values
boolproposeNew()
Proposes a new announcement
public
static proposeNew(string $title, string $text, DateTimeImmutable $validUntil) : self
Parameters
- $title : string
- $text : string
- $validUntil : DateTimeImmutable
Tags
Return values
selfreject()
Change status to rejected
public
reject(int $decidedBy) : void
Parameters
- $decidedBy : int
toArray()
Serialize to array (for database storage)
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>update()
Updates announcement data
public
update(string $title, string $text, DateTimeImmutable $validUntil[, AnnouncementStatus|null $status = null ][, int|null $decidedBy = null ]) : void
Parameters
- $title : string
- $text : string
- $validUntil : DateTimeImmutable
- $status : AnnouncementStatus|null = null
- $decidedBy : int|null = null
Tags
recordEvent()
private
recordEvent(DomainEvent $event) : void
Parameters
- $event : DomainEvent