z0s/console

Simple console framework to quickly create command line PHP scripts

Maintainers

Details

gitlab.com/z0s/console

Source

Issues

Installs: 24

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:composer-package

1.0.2 2022-10-17 14:55 UTC

This package is not auto-updated.

Last update: 2024-11-10 21:51:39 UTC


README

Installation

You can include it in your project using: composer require z0s/console

Requirements

  1. PSR-11 compatible container
  2. PHP8.0 or higher

bin/console example

<?php

$autoloaderPath = __DIR__ . '/../vendor/autoload.php';
if(!file_exists($autoloaderPath)) {
    throw new RuntimeException('Error, composer is not setup correctly.. Please run composer install');
}

$autoloader = require $autoloaderPath;

# Container
$container = new \League\Container\Container();

# Autowiring
$container->delegate(new \League\Container\ReflectionContainer());

# Load the CLI
$cli = new \z0s\Console\Console($container, $autoloader);

# Define the class scope to load commands from
$cli->setCommandsNamespace('z0s\\Commands');

# Define the name
$cli->setConsoleName('z0s');

# Define the version
$cli->setVersion('0.0.1');

# Run the cli
$cli->run();

Command example

<?php

namespace z0s\Commands;

/**
 * @property string $stringInput
 */
class Command extends \z0s\Console\ConsoleCommand
{
    protected string $signature = 'command {--stringInput=Hello World : Some string to pass into the command }';
    protected string $description = 'This is an example command';

    public function handle(): void
    {
        $this->out($this->stringInput);
    }
}