websk / php-console
CLI application integration for Slim Framework and GetOpt
2.3.0
2026-10-05 04:33 UTC
Requires
- php: ^8.3
- slim/psr7: ^1.8
- slim/slim: ^4.15
- ulrichsg/getopt-php: ^v4.0.4
Requires (Dev)
- phpstan/phpstan: ^2
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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-jsonandext-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.