v0.10.11
Object Hydration
This version introduced a couple of helper functions for transmitting PHP objects over the wire, and saving them in database records:
dehydrate()
- recursively converts an instance of a PHP class to a plain untyped object. Then, store the plain object in the database, or convert it to JSON and send it to a browser.hydrate()
- recursively converts a plain untyped object back to a PHP class instance. Use if after decoding a JSON received from the browser, or after loading a database record.
Example:
use function Osm\dehydrate;
use function Osm\hydrate;
...
$json = json_encode(dehydrate($order));
...
$order = hydrate(Order::class, json_decode($json));
In-depth look - in the blog post.
Reflecting Over Subtypes
From now on, you can retrieve subclasses marked with a #[Type]
attribute using new Class_::types
property:
global $osm_app; /* @var App $osm_app */
$productClass = $osm_app->classes[Product::class];
$dressClass = $productClass->types['dress'];