CLI kernel integration for DecodeLabs Genesis

v0.3.11 2024-04-26 17:39 UTC

This package is auto-updated.

Last update: 2024-04-26 17:40:03 UTC


README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

CLI kernel integration for DecodeLabs Genesis

Clip provides a framework for building comprehensive CLI based applications on top of Genesis.

Get news and updates on the DecodeLabs blog.

Installation

Install via Composer:

composer require decodelabs/clip

Usage

Clip is a middleware library that provides an out-of-the-box setup for implementing a Genesis based CLI task runner. This means you don't really interact with it much, except when setting up the core of your task running infrastructure.

Create your Hub

Define your Genesis Hub by extending Clip's abstract implementation:

namespace MyThing;

use DecodeLabs\Archetype;
use DecodeLabs\Clip\Controller as ControllerInterface;
use DecodeLabs\Clip\Hub as ClipHub;
use DecodeLabs\Clip\Task as TaskInterface;
use DecodeLabs\Veneer;
use MyThing;
use MyThing\Controller;
use MyThing\Task;

class Hub extends ClipHub
{
    public function initializePlatform(): void
    {
        parent::initializePlatform();

        // Load tasks from local namespace
        Archetype::map(TaskInterface::class, Task::class);

        // Create and load your controller (or use Generic)
        $controller = new Controller();
        $this->context->container->bindShared(ControllerInterface::class, $controller);
        $this->context->container->bindShared(Controller::class, $controller);

        // Bind your controller with Veneer
        Veneer::register(Controller::class, MyThing::class);
    }
}

With this hub in place, you can run tasks defined in your nominated namespace from the terminal via a bin defined in composer:

namespace MyThing;

use DecodeLabs\Genesis;
use MyThing\Hub;

require_once $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
Genesis::run(Hub::class);
{
    "bin": [
        "bin/thing"
    ]
}

Define your task:

namespace MyThing\Task;

use DecodeLabs\Clip\Task;

class MyTask implements Task
{
    public function execute(): bool
    {
        // Do the thing
        return true;
    }
}
composer exec thing my-task

# or with effigy
effigy thing my-task

Extending

Use the MyThing Controller Veneer frontage to run sub-tasks, and build on it to create your library's ecosystem with an easily accessed root.

See Effigy and Zest for examples.

Licensing

Clip is licensed under the MIT License. See LICENSE for the full license text.