Mapping¶
So far the User
aggregate only contains a string
property. By default Formal also supports these primitive types:
bool
int
string
?bool
?int
?string
Using primitive types is fine when you prototype the design of your aggregates. But you SHOULD use dedicated classes for each kind of value to better convey meaning and expected behaviour, this is what Typing is truely about. (1)
- It also has the benefit to immensely simplify refactoring your code.
Types are essential in the Formal design. You'll learn in the next chapter how to support your custom types.
By default Formal also supports:
Innmind\Immutable\Str
frominnmind/immutable
(1)Innmind\TimeContinuum\PointInTime
frominnmind/time-continuum
- Beware! It won't store the encoding, when fetched it will use
Innmind\Immutable\Str\Encoding::utf8
Note
Formal can support the PointInTime
type but you still need to declare it like this:
use Formal\ORM\{
Manager,
Definition\Aggregates,
Definition\Types,
Definition\Type\Support,
Definition\Type\PointInTimeType,
};
use Innmind\TimeContinuum\PointInTime;
$orm = Manager::of(
/* any adapter (1) */,
Aggregates::of(
Types::of(
Support::class(
PointInTime::class,
PointInTimeType::new($os->clock()),
),
),
),
);
- See the Adapters chapter to see all the adapters you can use.
The $os
variable comes from the innmind/operating-system
package.