Skip to content

Entities

Domain entities are "vanilla PHP objects". To simplify its model definition common fields and features are provided in the form of traits.

Entity Fields

Use entity fields to provide read operations for common entity fields. Built-in fields are:

  • Msgphp\Domain\Model\CreatedAtField
  • Msgphp\Domain\Model\LastUpdatedAtField

Entity Features

Use entity features to provide write operations for common entity fields. Built-in features are:

  • MsgPhp\Domain\Model\CanBeConfirmed
  • MsgPhp\Domain\Model\CanBeEnabled

Basic Example

<?php

use MsgPhp\Domain\Model\CreatedAtField;
use MsgPhp\Domain\Model\CanBeEnabled;

// --- SETUP ---

class MyEntity
{
    use CreatedAtField;
    use CanBeEnabled;

    public function __construct()
    {
        $this->createdAt = new \DateTimeImmutable();
    }
}

// --- USAGE ---

$entity = new MyEntity();
$createdAt = $entity->getCreatedAt();

if (!$entity->isEnabled()) {
    $entity->enable();
}