Download the PHP package matthiasnoback/broadway-serialization without Composer
On this page you can find all versions of the php package matthiasnoback/broadway-serialization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matthiasnoback/broadway-serialization
More information about matthiasnoback/broadway-serialization
Files in matthiasnoback/broadway-serialization
Package broadway-serialization
Short Description Serialization helpers for Broadway
License MIT
Homepage http://github.com/matthiasnoback/broadway-serialization
Informations about the package broadway-serialization
Broadway Serialization helper library
By Matthias Noback
Event-sourcing framework Broadway requires a lot of your objects (like domain events and often view models as well) to be serializable because they have to be stored in plain text and later be reconstituted.
Making an object serializable requires you to write lots of pretty simple code. Even though that code is simple, you are likely to make mistakes in it. It's also a bit boring to write. To alleviate the pain, this library helps you to make objects serializable with in a few simple steps.
Installation
Just run
composer require matthiasnoback/broadway-serialization
Conventions
This library is very simple and it just works because of a few simple and yet assumptions:
- Serializable objects have at least one property. Properties can have any kind of scope.
- Serializable objects implements Broadway's
Serializable
interface. - Properties contain scalar values, serializable objects, or arrays of serializable objects.
Example
By implementing deserializationCallbacks()
you can define callables that
should be called in order to deserialize the provided data. The callable will
be called once for single values or multiple times for arrays of values.
Setup
The Serializable
trait depends on a little bit of setup. Before calling its deserialize()
method, make sure you
have properly set up a Reconstitute
service, like this:
Note that this package ships with different implementations of the hydrator. Depending on your setup and preferences, you can also use the HydrateUsingClosure
class. The former generally performs better than the HydrateUsingReflection
.
Performance
When using this library, your personal performance will increase significantly. Of course, runtime performance will be worse (not noticeably though, unless you're actually deserializing millions of objects).