crudle/entity

A set of Entity assistance components

v1.0 2016-10-24 18:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:18 UTC


README

This package contains various things like traits for private immutable attributes, and making entities identifiable with UUID's.

Installation

composer require crudle/entity

Example Usage

use Crudle\Entity\Identity\IdentifiedByUuid;
use Crudle\Entity\Property\PrivateImmutableAttributes;

class MyEntity
{
    use IdentifiedByUuid, PrivateImmutableAttributes;

    /**
     * @param string $description
     * @return MyEntity
     */
    public function setDescription(string $description): MyEntity
    {
        return $this->set('description', $description);
    }

    /**
     * @return string
     * @throws \Crudle\Entity\Exception\UndefinedException
     *  When a description has not yet been set
     */
    public function getDescription(): string
    {
        return $this->getOrFail('description');
    }
}

$myEntity = new MyEntity;
$myEntity->getId(); // Crudle\Entity\Identity\Uuid

$myOtherEntity = new MyEntity('fa8588c6-166d-400d-9b13-561704027e94');