Download the PHP package jeckel-lab/contract without Composer
On this page you can find all versions of the php package jeckel-lab/contract. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeckel-lab/contract
More information about jeckel-lab/contract
Files in jeckel-lab/contract
Package contract
Short Description Contract / Interfaces used by other packages and DDD projects
License MIT
Informations about the package contract
Jeckel-Lab Contract
List of interfaces use as contract in other packages or DD projects
This contract includes some strong typings, object relation and psalm validation.
Require *`php >= 7.2.** and **
php >= 8.0`**
Release name | Branch name | Php Version |
---|---|---|
1.x | release/1.X | php >= 7.2 & php <= 8.0 |
2.x | master | php >= 8.0 |
Documentation for version 2.x (php >= 8.0)
Domain
Domain contract are part of DDD implementation suggestion, it's not required and is not linked to any frameworks.
Identity
Identity are used to define a unique identifier for an Entity or a RootAggregate.
Identity must be:
- immutable
- final
- constructor should be private, use a factory method:
new
==> Generate (if possible) a new Identity object with a random value (like UUIDs)from
==> Instantiate Identity from an existing value
See detailed implementation proposal: jeckel-lab/identity-contract
Entity
Entity: main Entity contract
Entity must have an Id implementing the Identity
interface.
Don't forget to use @psalm templates
Event
Event are notification about what happened during a use case.
Event must be:
- immutable
DomainEventAware
Entities and root aggregates handle domain events. To facilitate this behaviour, you can use this interface and trait:
- DomainEventAwareInterface
- DomainEventAwareTrait
This interface defines two methods:
addDomainEvent
allow you to register new event occurred during a Use Case.popEvent
will empty the entity's event list at the end of a use case to dispatch them into an Event Dispatcher.
Just use the interface and trait into your entity:
And if you use the CommandBus pattern, then you can add events to the response easily:
ValueObject
Using ValueObject
to embed a value (or group of value for complex types) as an object allow you:
- to use strong typing in the application (a
Speed
can not be mixed with any random float) - to embed data validation (be sure that the
Speed
is always a positive value, is lower than a reasonable value, etc.)
Value object must be defined as:
- immutable (one's instantiated, they should not be modified unless a new instance is created).
- final
- constructor should be private, use the static
from
method as a factory - when requesting to ValueObject with same value,
from
should return the same instance
Think about implementing it like this:
Core
To be completed
Command Dispatcher
To be completed
See detailed implementation proposal: jeckel-lab/command-dispatcher
Query Dispatcher
To be completed
See detailed implementation proposal: jeckel-lab/query-dispatcher
Exceptions
Each layer has it's own Exception interface that extends Throwable
:
- Core: CoreException
- Domain: DomainException
- Infrastructure: InfrastructureException
- Presentation: PresentationException
In each layer, when we need to throw an Exception, we create a new class corresponding to the type of Exception. This class must:
- extends one of the SPL exception or another (more generic) exception from the same namespace.
- implements the exception interface of the current layer.