Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yannoff/console
A lightweight, simple alternative to symfony/console, designed for easy PHP applications development.
https://github.com/yannoff/console
console php-applications php-cli symfony
Last synced: 3 months ago
JSON representation
A lightweight, simple alternative to symfony/console, designed for easy PHP applications development.
- Host: GitHub
- URL: https://github.com/yannoff/console
- Owner: yannoff
- License: mit
- Created: 2019-05-31T18:34:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-09T22:39:13.000Z (11 months ago)
- Last Synced: 2024-03-10T21:35:42.407Z (11 months ago)
- Topics: console, php-applications, php-cli, symfony
- Language: PHP
- Homepage:
- Size: 126 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yannoff/console
A simple, lightweight console implementation for command-line PHP applications.
[![Latest Stable Version](https://poser.pugx.org/yannoff/console/v/stable)](https://packagist.org/packages/yannoff/console)
[![Total Downloads](https://poser.pugx.org/yannoff/console/downloads)](https://packagist.org/packages/yannoff/console)
[![License](https://poser.pugx.org/yannoff/console/license)](https://packagist.org/packages/yannoff/console)## Why are we here ?
This library was conceived as an alternative to the [symfony/console](https://github.com/symfony/console) component.
Truth is, the symfony component may be good for rapid-application-development or for a proof-of-concept, but on the other hand doesn't seem to be the best option for most use-cases, since only a few among the plenty of available features are necessary.
So here came the need for the [yannoff/console](https://github.com/yannoff/console) component.
Yet the idea was not to [reinvent the wheel](https://sourcemaking.com/antipatterns/reinvent-the-wheel), but merely to provide
a simpler, lighter (in size & resource) and more POSIX-compliant implementation for PHP command-line applications.## Installation
Via [composer](https://getcomposer.org/):
```bash
$ composer require yannoff/console
```## Usage
Here is a _Hello World_ command example:
First the application script, the script that will be invoked using `php bin/app.php`
```php
#!/usr/bin/env php
addCommands([
new HelloCommand('hello'),
]);$application->run();
```Then the command file:
```php
setName('hello')
->setHelp('Hello world')
->setDescription('Hello world demo application')
->addArgument(
'name',
Argument::OPTIONAL,
'Optional name to greet'
)
->addOption(
'upper',
'u',
Option::FLAG,
'Print the greetings in upper case'
)
;
}public function execute()
{
$name = $this->getArgument('name');
$upper = $this->getOption('upper');$message = 'Hello ' . (null === $name ? 'World' : $name);
if ($upper) {
$message = strtoupper($message);
}$this->write($message);
return 0;
}
}```
People willing to migrate from symfony/console may want to have a look at the [migration](doc/migrating.md) section of the documentation.
## Licence
Licensed under the [MIT Licence](LICENSE).