Tasks are executable units of management logic. They are defined by the
abstract class Valvoid\Fusion\Tasks\Task and can be added or removed
through config files.
Note
This example builds on the Custom Package Manager Example.
The nested Fusion content from the required base example, which we will use here, looks like this (other files not shown for simplicity):
dependenciesvalvoid/fusion: Nested Fusion packagesrc/Tasks/Task.php: Abstract class file
Loadable Task Code
To implement a simple hello-world-style executable unit that prints its class
name, we create the Basic.php file with the following dummy
lazy code:
namespace Valvoid\Package\Tasks\Basic;
use Valvoid\Fusion\Tasks\Task;
class Basic extends Task
{
public function execute(): void
{
echo self::class . "\n";
}
}
Located at the following path within the project:
dependenciesvalvoid/fusion: Nested Fusion packagesrc/Tasks/Task.php: Abstract class file
src: Identifier segments prefixTasks/Basic: WrapperBasic.php: Our custom class
From anywhere inside the project directory, register the lazy code by
running the lightweight
register command:
fusion register
Custom Config Layer
To add the registered code to the common Fusion config, we create the
tasks.php file with the following content:
use Valvoid\Package\Tasks\Basic\Basic;
return [
"tasks" => [
"basic" => Basic::class
]
];
Located at the following path within the project:
config: Directory mapped in extension logictasks.php: Custom config
dependenciesvalvoid/fusion: Nested Fusion packagesrc/Tasks/Task.php: Abstract class file
src: Identifier segments prefixTasks/Basic: WrapperBasic.php: Our custom class
The config now defines a task with the basic ID, which you can run as a
command:
custom-fusion basic