Download the PHP package phore/hydrator without Composer
On this page you can find all versions of the php package phore/hydrator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phore/hydrator
More information about phore/hydrator
Files in phore/hydrator
Package hydrator
Short Description Unserialize arrays into object structure
License MIT
Informations about the package hydrator
phore-hydrator
serialize / unserialize plain into object structures. Hydrator parses the DocComments of public properties and instanciates the classes according to the definiton.
Examples:
- hydrator-usage-example.php
Installation:
Basic Example
$userData is a UserData Object and all properties casted correctly
to desired types specified in DocComments.
Recognized Annotations
- Simple types like
string,int,bool,float,array - Array types like
string[],int[]... - Object types
OtherClass - Arrays of Objects
OtherClass[] - Nullable properties
type|null
Guide
Getters / Setters
On objects, hydrator will try to set property values in the following order:
1) If object has a set<PropertyName>($value)-Method it will use it first
2) If the property is public it will be set directly
3) If there is a __set($name, $value) method it will be used
Default Values
Default values will be applied if no data was found for the specific key
Optional Properties
You can define a property as optional by adding |null to the
DocBlock.
If the input data was not found, the value will be null.
Filter input data before hydration
To ease backwards compatibility issues, the magick __hydrate() method
is called to prefilter the input data before it is hydrated.
Dealing with additional / undefined input data
By default, on undefined input keys, hydrator will throw an exception. You can toggle this behaviour