search hotlink icon profile hotlink icon

This page explains lifecycle by building upon the extensions example. For the complete result of this example, see the GitLab repository. Note that this repository contains content for other examples as well, as the documentation uses a single package for all examples.

On This Page

Metadata

Modify the content in the production file fusion.json as follows:

                {
    "name": "Package",
    "description": "Basic example package.",
    "id": "valvoid/package",
    "version": "0.1.0",
    "structure": {
        "gitlab.com/valvoid/'fusion/'php": "package/==1.0.0-dev:main",
        "/cache": "cache",
        "/extensions/config": "extension",
        "/public": "state",
        "/dependencies": [
            "valvoid.com/valvoid/fusion/1.0.0"
        ]
    },
    "environment": {
        "php": {
            "version": "8.1.0"
        }
    },
    "lifecycle": {
        "migrate": "/lifecycle/migrate.php"
    }
}
            

Migrate Script

Since other callbacks are subsets of the more interesting "on migrate" callback, let's focus on creating that one.

Create the /lifecycle directory in the root of your package, and within that directory, create the migrate.php file with the following content:

                <?php

if (isset($dir) && isset($version)) {

    // your migrate logic
    // say hi and
    // show lower package source directory and version
    trigger_error(
        "Hi, on migrate callback here. " .
        "dir: $dir, version: $version.",

        // actually default
        E_USER_NOTICE
    );
}

// nothing done
// run Fusion's default logic
return false;
            

Temporary Package

In this example, the package contains multiple environments that have been locked by resetting the root source. As a result, you cannot directly build the package with modifications. To apply and test modifications, copy the whole package content into a new directory. Inside the fusion.dev.php remove the source part:

                <?php

// metadata array
return [
    "structure" => [

        // directory prefix segments
        // relative to package root
        "/cache/loadable/tests" => "Valvoid\Package\Tests"
    ]
];
            

Now, inside the new package, execute the following build command:

                php fusion build
            

Since the root source contains an offset reference 1.0.0-dev larger than the metadata version 0.1.0, you can execute this command repeatedly, applying and testing your changes without further resets.