Releases: osmphp/core
v0.10.18
Better Inheritance Reflection
Navigate inheritance hierarchies easier using new parent_class_name, parent_class, and child_class_names properties of the Class_ reflection:
global $osm_app;
echo $osm_app->classes[App::class]->parent_class->name;
// Osm\Core\Object
Fixes
The osmc and gulp provide an informative error message about unfinished @property definitions like this:
/**
* @property
*/
class Foo extends Object_ {
}
v0.10.15
The new release contains PHP 8.1 compatibility fixes.
v0.10.14
Method Reflection
From now on, you can reflect over class methods. For example:
global $osm_app; /* @var App $osm_app */
$class = $osm->app->classes[Product::class];
$method = $class->methods['join_category'];
foreach ($method->parameters as $parameter) {
...
}
Conditional Serialization
There are properties that should be sometimes serialized, and sometimes not. For example, consider Scope class. If you query title and parent.title, then the parent property should be serialized:
{
"title": "Child scope",
"parent": {
"title": "Parent scope"
}
}
However, if you decide to store all scopes in a tree-like model, then parent property should not be serialized:
{
"title": "Parent scope",
"children": [
{
"title": "Child scope"
// not parent property
}
]
}
For such properties, use not_having conditional serialization:
/**
* @property Scope $parent #[Serialized(not_having: 'children')]
* @property Scope[] $children #[Serialized]
*/
class Scope extends Object_ {
}
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'];
v0.10.4
This minor update contains:
- New
AttributeRequiredexception. Throw it if you expect a class or a property to have certain PHP attribute applied. - New
module_class_namereflection property. It specifies the module that introduced a given class or property.
v0.10.1
A single fix has been made that allows using static::new() in your classes.
v0.10.0
New Way Of Applying Dynamic Traits
From now on, Module::$traits property is obsolete. Instead, specify the class you are extending directly in the dynamic trait class using #[UseIn] attribute:
use Osm\Core\Attributes\UseIn;
...
#[UseIn(Foo::class)]
trait FooTrait
{
}
Sorting By Dependency
Application packages, modules, themes and data source indexers are all sorted by dependency using new sort_by_dependency() helper function. Calling this function may seem a bit clunky, but it does the job:
return sort_by_dependency($packages, 'Packages',
fn($positions) =>
fn(Package $a, Package $b) =>
$positions[$a->name] <=> $positions[$b->name]
);
Objects that are being sorted should have unique name, and after - am array of object names it should go after:
/**
* @property string $name
* @property string[] $after
* ...
*/
class Package extends Object_ {
}
v0.9.2
v0.9.1
The new version allows introspecting all modules and classes of
the project regardless to which application they belong. Use it as follows:
use Osm\Project\App;
...
$result = [];
Apps::run(Apps::create(App::class), function (App $app) use (&$result) {
// use $app->modules and $app->classes to introspect
// all modules and classes of the projects and its
// installed dependencies
// put the introspection data you need into `$result`. Don't reference
// objects of the `Osm_Project` application, as they'll won't work
// outside this closure. Instead, create plain PHP objects and arrays,
// and fill them as needed
});
Notice. The Osm_Project application is for introspection only. Invoking user code in context of this application may produce unexpected results.
v0.8.12
This version comes with a compiler fix. Osm\Runtime\Compilation\CompiledApp class has several properties listing its modules, a bit different from the previous version:
unsorted_modulesreturns all modules found in the project and its dependencies.referenced_modulesreturns only thoseunsorted_modulesthat actually belong to the application, either directly specified in the module file, or in a module that depends on it.modulesreturnsreferenced_modulessorted by dependency.