Search by

websk / php-console

websk

CLI application integration for Slim Framework and GetOpt

Package info

github.com/websk/php-console

pkg:composer/websk/php-console

Statistics

Installs: 88

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

2.3.0 2026-10-05 04:33 UTC

This package is auto-updated.

Last update: 2026-10-05 04:34:32 UTC


README

websk/php-console connects GetOpt.PHP commands with a Slim application and a PSR-11 container.

Requirements

  • PHP 8.3 or newer, including PHP 8.5
  • Composer 2
  • ext-json and ext-mbstring

Installation

composer require websk/php-console

Usage

Create a PSR-11 container, register commands, and call execute() with CLI arguments. Passing no arguments to execute() uses $_SERVER['argv'].

<?php

use GetOpt\Command;
use GetOpt\GetOpt;
use Psr\Container\ContainerInterface;
use WebSK\Console\ConsoleApp;

require __DIR__ . '/vendor/autoload.php';

$container = new class implements ContainerInterface {
    public function get(string $id): mixed
    {
        throw new InvalidArgumentException("Unknown service: {$id}");
    }

    public function has(string $id): bool
    {
        return false;
    }
};

$app = new ConsoleApp($container);
$app->addCommand(new Command(
    'hello',
    static function (GetOpt $getOpt): void {
        echo "Hello!\n";
    }
));

$app->execute();

Run it with:

php console.php hello

ConsoleApp::run() is intentionally disabled because this package is for CLI applications. Use ConsoleApp::execute() instead.

Development

Install all dependencies and run the complete validation suite:

composer install
composer check
composer validate --strict
composer check-platform-reqs
composer audit --locked

The composer check command runs PHP lint, PHPUnit, and PHPStan level 8.

License

This package is available under the MIT License.