https://github.com/xy2z/cliclass
Easily create a simple CLI tool from PHP classes
https://github.com/xy2z/cliclass
cli cli-framework php
Last synced: 4 months ago
JSON representation
Easily create a simple CLI tool from PHP classes
- Host: GitHub
- URL: https://github.com/xy2z/cliclass
- Owner: xy2z
- Created: 2018-10-23T14:02:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T19:27:45.000Z (about 5 years ago)
- Last Synced: 2025-07-24T10:31:16.767Z (10 months ago)
- Topics: cli, cli-framework, php
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CliClass
(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
```php
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
```bash
$ php cli.php
Usage:
command [arguments]
Available commands:
hello_world Says hello world.
hello Says hello to $name.
```
```bash
$ php cli.php hello_world
Hello world.
```
```bash
$ php cli.php hello
Usage: hello
Error: Missing argument 2 for $name (no default value)
```
```bash
$ php cli.php hello Peter
Hello Peter
```