decodelabs/clip

DecodeLabs Genesis 的 CLI 内核集成

v0.3.15 2024-09-04 19:57 UTC

README

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

DecodeLabs Genesis 的 CLI 内核集成

Clip 提供了一个框架,用于在 Genesis 的基础上构建基于 CLI 的全面应用程序。

DecodeLabs 博客 上获取新闻和更新。

安装

通过 Composer 安装

composer require decodelabs/clip

使用方法

Clip 是一个中间件库,提供了一套现成的设置,用于实现基于 Genesis 的 CLI 任务运行器。这意味着你不需要与它进行太多交互,除非在设置任务运行基础设施的核心时。

创建您的 Hub

通过扩展 Clip 的抽象实现来定义您的 Genesis Hub

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);
    }
}

有了这个 hub,您可以通过 composer 中定义的 bin 从终端运行您指定的命名空间中定义的任务

namespace MyThing;

use DecodeLabs\Genesis;
use MyThing\Hub;

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

定义您的任务

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

扩展

使用 MyThing 控制器界面来运行子任务,并在此基础上构建您库的生态系统,并提供易于访问的根目录。

请参阅 EffigyZest 的示例。

许可

Clip 根据 MIT 许可证进行许可。有关完整许可证文本,请参阅 LICENSE