https://github.com/jabernardo/console.php
Command-line Application Skeleton for PHP
https://github.com/jabernardo/console.php
command-line command-line-arguments-parser php-cli
Last synced: 10 days ago
JSON representation
Command-line Application Skeleton for PHP
- Host: GitHub
- URL: https://github.com/jabernardo/console.php
- Owner: jabernardo
- License: mit
- Created: 2018-02-18T13:38:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-04-02T13:01:00.000Z (almost 5 years ago)
- Last Synced: 2025-06-04T02:45:33.996Z (8 months ago)
- Topics: command-line, command-line-arguments-parser, php-cli
- Language: PHP
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# console.php
`console.php` is a skeleton for php command-line application.
```php
#!/usr/bin/php
hasOptions(['name', 'age'])) {
$o->writeln('Invalid args.');
return;
}
$o->writeln('Hello %s! So you are %d years old.', $i->getOption('name'), $i->getOption('age'));
}
}
// Instantiate a new console application
$app = new \Console\Application();
// Register our test HelloCommand to our console application
$app->add('hello', new HelloCommand());
// You can also just declare a command by using callables
$app->add('help', function($i, $o) {
$o->writeln('This is a sample application.');
}, true); // <-- `true` is to enable this as the default command
// Finally, App and Running!
$app->run();
```
## Input
### hasFlag `:boolean`
Check if flag was passed on application.
```php
hasFlag('q')) {
// Do something
}
}
}
```
### hasOption `:boolean`
Check if option was passed on application.
```php
hasOption('max')) {
// Do something
}
}
}
```
### hasOptions `:boolean`
Check if option(s) was passed on application.
```php
hasOptions(['age', 'name'])) {
// Do something
}
}
}
```
### getOption `:mixed`
Returns the value of option being passed on.
```php
hasOption('max')) {
$this->max = $i->getOption('max');
}
}
}
```
### getOptions `:array`
Returns all options.
```php
getOptions();
}
}
```
### setOptionDelimeter `:void`
Set option delimeter (default value is `:`)
```php
setOptionDelimeter('=');
$options = $i->getOptions();
}
}
```
### getOptionDelimeter `:string`
Get option delimeter (default value is `:`)
### getParameters `:array`
Returns all parameters.
```php
getParameters();
}
}
```
## Output
### write `:void`
Write string buffer.
```php
write('Hello %s!', $i->getOption('name'));
}
}
```
### writeln `:void`
Write a line of string.
```php
write('Hello %s! So you\'re %d years old.', $i->getOption('name'), $i->getOption('age'));
}
}
```
## License
The `console.php` is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).