Download the PHP package done-super-app/cereal without Composer
On this page you can find all versions of the php package done-super-app/cereal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download done-super-app/cereal
More information about done-super-app/cereal
Files in done-super-app/cereal
Package cereal
Short Description A package to simplify serialization management.
License MIT
Informations about the package cereal
Cereal
Cereal is a PHP package that allows you to easily serialize and deserialize your data.
Installation
You can install the package via composer:
Usage
To start using the package, you need to create a class that implements the DoneSuperApp\Cereal\Contracts\Serializable interface, and use the DoneSuperApp\Cereal\Cereal trait which
contains some helpers for a default configuration.
The serializes method returns an array of the properties that you want to serialize. Then the package will automatically serialize and deserialize the data based on the type
hinted properties.
Note
- The package will only serialize public properties that are type hinted.
- The package will serialize properties in the order they are defined in the
serializemethod.
Serialization Handlers
In most uses cases, you will need to serialize and deserialize some properties in a different way. For example, you may want to serialize a DateTime object to a timestamp, or
serialize a User object to an array or something.
For that, you're going to create your own serialization handler and add it to the DoneSuperApp\Cereal\SerializationHandlerFactory.
In the above example, when trying to serialize a user object, we serialize only the ID, and when trying to deserialize it, we fetch it again from database.
Then, you need to add your handler to the DoneSuperApp\Cereal\SerializationHandlerFactory:
Now, when working with our object that will be serialized, and if it contains a User instance, it will automatically be serialized and deserialized using our handler.
Laravel Bridge
// TODO