DecodeLabs dev log

DecodeLabs dev log

Development log - 2022/44

Development log - 2022/44

Effigy

Tom Wright's photo
Tom Wright
·Nov 4, 2022·

2 min read

This week sees another new addition to the roster: Effigy.

Unlike most other DecodeLabs libraries, Effigy is not directly installed in your project. Instead, it should be installed globally (with your composer bin path in your $PATH) so that it can be called from anywhere.

It will then try and load your main CLI entry point via config in your composer.json, with path template parameters if needed, load your project, then get out of your way.

Say for example, you currently run commands in your project though webroot/index.php as your primary entry point:

php webroot/index.php run-task

Define your entry point in your composer.json file:

{
    "extra": {
        "effigy": {
            "entry": "webroot/index.php"
        }
    }
}

Then you can run CLI commands available in your project via the effigy executable directly:

effigy run-task

Should you need per-environment entry files, specify template keys in your composer config:

{
    "extra": {
        "effigy": {
            "entry": "entry/{{env}}.php"
        }
    }
}

Then on first run, Effigy will ask for the "env" parameter and save it in a local config file (which gets added to your .gitignore).

PHP binary

Effigy can use alternative versions of PHP on a per-project basis:

effigy set-php
> php8.1

The bin path is stored in your local config and all process launches will use this going forward. Reset it to "php" to use the default system global binary.

PHP versions

All libraries are now properly testing under PHP8.0, PHP8.1 and PHP8.2 - previously PHP8.1 was sort of in place, but not analysing properly, and 8.2 was not being taken into consideration at all.

Going forward, all libraries should work under all three of these versions, with PHP8.1 being the target minimum version requirement at some point in the next 6 months or so, once 8.2 is out.

Dictum conditional returns

A small update to Dictum makes use of PHPStan's conditional return types to ensure if a non-null value is passed to any of the text formatting methods, a non-null value is returned.

This brand of update will be extended to other libraries that provide similar nullable interfaces shortly.

Pandora

A small but important update to Pandora ensures that the correct PHPStan type is returned from ->get() calls and array accesses when using the fully qualified interface as key.

This ensures that you don't need to do any type checking in your code to appease PHPStan when accessing your contained objects.

// PHPStan now understands $myObject is a MyInterface
$myObject = $container->get(MyInterface::class);
// or
$myObject = $container[MyInterface::class];
 
Share this