Download the PHP package cjsaylor/libdomain without Composer
On this page you can find all versions of the php package cjsaylor/libdomain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cjsaylor/libdomain
More information about cjsaylor/libdomain
Files in cjsaylor/libdomain
Package libdomain
Short Description PHP classes and traits to facilitate domain driven design.
License MIT
Informations about the package libdomain
libdomain
Libdomain is a php library to facilitate domain driven development.
Core concepts
This library contains the following abstract classes:
Entity
- An entity is an identifiable object.ValueObject
- An object who's values are immutable.Collection
- A collection ofEntity
objects.CollectionEntity
- An entity object that also acts as a collection (an identifiable collection).
In cases where the abstract classes can't be extended, all functionality of the abstract classes are provided
with traits. For example, if you wanted an existing entity to have the properties of a ValueObject
, then you would
use the ReadAccessable
trait:
The ConcreteEntity
would now be an immutable value object.
Examples
Entity Example
The first example illustrates a user object that accepts an email
attribute that must be an immutable email value object.
CollectionEntity example
This next example will illustrate a group of users where that group also has an identity.
Here we will make use of the CollectionEntity
which is both a Collection
and an Entity
.
It will make use of the User
entity defined in the first example.
Setter callback example
Let's modify the User
object with some custom setter callbacks (available in 1.0.1
).
This allows us to typehint (and do other custom set logic for the Email
value object).
Concrete entities example
In some instances, we don't want extra properties to be set on our entities. To limit the properties
that can be set on an entity, the PropertyLimitable
interface/trait can be implemented: