xy2z / cliclass
Create a simple CLI tool from a PHP class
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 6
pkg:composer/xy2z/cliclass
Requires
- wujunze/php-cli-color: ^2.4
This package is auto-updated.
Last update: 2025-09-29 02:57:47 UTC
README
(previously known as SlimConsole)
Create a simple CLI tool from a PHP class.
- All public methods will be available to run from cli.
- PHPdocs will be displayed as the description.
- Method arguments are automatically validated.
- Supports multiple classes.
Requires
- PHP 7.0 or above
Install
composer require xy2z/cliclass
Usage
require '/path/to/vendor/autoload.php'; use xy2z\CliClass\CliClass; class Router { /** * Says hello world. */ public function hello_world() { echo 'Hello world.'; } /** * Says hello to $name. */ public function hello(string $name) { echo 'Hello ' . $name; } } CliClass::init($argv, [ Router::class, ]);
Result
$ php cli.php Usage: command [arguments] Available commands: hello_world Says hello world. hello <string $name> Says hello to $name.
$ php cli.php hello_world Hello world.
$ php cli.php hello Usage: hello <string $name> Error: Missing argument 2 for $name (no default value)
$ php cli.php hello Peter Hello Peter