Skip to content

Releases: osmphp/core

v0.10.18

18 Feb 09:17
Compare
Choose a tag to compare

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_ {
}

Related Releases

v0.10.15

14 Jan 10:01
Compare
Choose a tag to compare

The new release contains PHP 8.1 compatibility fixes.

Related Releases

v0.10.14

02 Dec 16:38
Compare
Choose a tag to compare

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_ {
} 

Related Releases

v0.10.11

19 Nov 09:28
Compare
Choose a tag to compare

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']; 

Related Releases

v0.10.4

05 Nov 11:58
Compare
Choose a tag to compare

This minor update contains:

  • New AttributeRequired exception. Throw it if you expect a class or a property to have certain PHP attribute applied.
  • New module_class_name reflection property. It specifies the module that introduced a given class or property.

Related Releases

v0.10.1

22 Oct 07:58
Compare
Choose a tag to compare

A single fix has been made that allows using static::new() in your classes.

Related Releases

v0.10.0

08 Oct 11:07
Compare
Choose a tag to compare

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_ {
}   

Related Releases

v0.9.2

23 Sep 18:29
Compare
Choose a tag to compare
  • minor: osmh utility doesn't require a parameter anymore, and the generated hint file reports fewer warnings

v0.9.1

12 Sep 15:12
Compare
Choose a tag to compare

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

27 Aug 08:26
Compare
Choose a tag to compare

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_modules returns all modules found in the project and its dependencies.
  • referenced_modules returns only those unsorted_modules that actually belong to the application, either directly specified in the module file, or in a module that depends on it.
  • modules returns referenced_modules sorted by dependency.

Full Status Report