https://github.com/decodelabs/clip
CLI kernel integration for DecodeLabs Genesis
https://github.com/decodelabs/clip
cli kernel php
Last synced: about 1 year ago
JSON representation
CLI kernel integration for DecodeLabs Genesis
- Host: GitHub
- URL: https://github.com/decodelabs/clip
- Owner: decodelabs
- License: mit
- Created: 2022-11-22T11:08:03.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2025-04-14T08:44:09.000Z (about 1 year ago)
- Last Synced: 2025-04-15T14:07:03.651Z (about 1 year ago)
- Topics: cli, kernel, php
- Language: PHP
- Homepage:
- Size: 62.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Clip
[](https://packagist.org/packages/decodelabs/clip)
[](https://packagist.org/packages/decodelabs/clip)
[](https://packagist.org/packages/decodelabs/clip)
[](https://github.com/decodelabs/clip/actions/workflows/integrate.yml)
[](https://github.com/phpstan/phpstan)
[](https://packagist.org/packages/decodelabs/clip)
### CLI kernel integration for DecodeLabs Genesis
Clip provides a framework for building comprehensive CLI based applications on top of [Genesis](https://github.com/decodelabs/genesis).
---
## Installation
Install via Composer:
```bash
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 directly, except when setting up the core of your task running infrastructure.
### Create your Hub
Define your Genesis Hub by extending Clip's abstract implementation:
```php
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\Monarch;
use DecodeLabs\Pandora\Container;
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)
if(Monarch::$container instanceof Container) {
$controller = new Controller();
Monarch::$container->bindShared(ControllerInterface::class, $controller);
Monarch::$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:
```php
namespace MyThing;
use DecodeLabs\Genesis\Bootstrap\Bin as BinBootstrap;
use MyThing\Hub;
require_once $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
new BinBootstrap(Hub::class)->run();
```
```json
{
"bin": [
"bin/thing"
]
}
```
Define your task:
```php
namespace MyThing\Task;
use DecodeLabs\Clip\Task;
class MyTask implements Task
{
public function execute(): bool
{
// Do the thing
return true;
}
}
```
```bash
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](https://github.com/decodelabs/genesis) and [Zest](https://github.com/decodelabs/zest) for examples.
## Licensing
Clip is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.