https://github.com/elfsundae/console
CLI library based on Laravel Console for creating PHP console application.
https://github.com/elfsundae/console
Last synced: 12 months ago
JSON representation
CLI library based on Laravel Console for creating PHP console application.
- Host: GitHub
- URL: https://github.com/elfsundae/console
- Owner: ElfSundae
- License: mit
- Created: 2017-08-13T19:12:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-20T14:07:38.000Z (almost 9 years ago)
- Last Synced: 2025-03-22T08:02:44.774Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/elfsundae/console)
[](LICENSE.md)
[](https://travis-ci.org/ElfSundae/console)
[](https://styleci.io/repos/100198819)
[](https://insight.sensiolabs.com/projects/4658ebb9-710d-40fb-9573-1d8ada1991b4)
[](https://scrutinizer-ci.com/g/ElfSundae/console)
[](https://scrutinizer-ci.com/g/ElfSundae/console/?branch=master)
[](https://packagist.org/packages/elfsundae/console)
CLI library based on [Laravel Console][Laravel Artisan] for creating PHP console application.
## Installation
```sh
$ composer require elfsundae/console
```
## Usage
First, create a PHP script and make it executable:
```php
#!/usr/bin/env php
run();
```
Then, you can register commands using `add` or `command` method.
The `add` method accepts an `Illuminate\Console\Command` instance or a `Symfony\Component\Console\Command\Command` instance. The `command` method may be used for register a Closure based command, it accepts three arguments: the command signature, a Closure which receives the commands arguments and options, and the optional description of the command.
```php
class Example extends Illuminate\Console\Command
{
protected $signature = 'example
{--foo=bar : The "foo" option description}';
protected $description = 'Example command description';
public function handle()
{
$this->comment($this->option('foo'));
}
}
$app->add(new Example);
$app->command('title {username}', function ($username) {
$this->comment(title_case($username));
}, 'The `title` command description');
```
To build a single command application, you may pass `true` to the second argument of the `setDefaultCommand` method, or just call the `runAsSingle` method:
```php
(new ElfSundae\Console\Application)
->add($command = new Example)
->getApplication()
->setDefaultCommand($command->getName(), true)
->run();
```
```php
(new ElfSundae\Console\Application)
->add(new Example)
->getApplication()
->runAsSingle();
```
## Documentation
- [Laravel Artisan][]
- [Symfony Console Component][]
## Testing
```sh
$ composer test
```
## License
This package is open-sourced software licensed under the [MIT License](LICENSE.md).
[Laravel Artisan]: https://laravel.com/docs/artisan
[Symfony Console Component]: http://symfony.com/doc/current/components/console.html