Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Serialization

The Smooth PHP CQRS ES framework comes with a simple serializer, designed to get you started as quickly as possible. Usage of the serializer will allow you to quick convert complex DTO's to simple associative arrays.

Examples

<?phpnamespaceApp;
useSmoothPhp\Contracts\Serialization\Serializable;
class MyDTO implements Serializable {
publicfunction__construct(Id$id, DateTime$creationDate) {
$this->id = $id;
$this-creationDate = $creationDate;
}
// getterspublicfunctionserialize()
{
return [
'id' => (string) $this->id,
'date' => $this->creationDate->serialize(),
];
}
publicstaticfunctiondeserialize(array$data)
{
returnnewstatic(
newId($data['id']),
DateTime::deserialize($data['date'])
);
}
}
$dto = newApp\MyDTO(newApp\Id(uuid()), App\DateTime::now());
$serializer = new \SmoothPhp\Serialization\ObjectSelfSerializer;
// Store in database, job queue, etc$serialized = $serializer->serialize($dto);
// Use in app$object = $serializer->deserialize($serialized);

About

[READ ONLY] Smooth PHP CQRS/ES Serialization

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages