https://github.com/10quality/ayuco
Command-Line interface that can be used to execute commands written in PHP.
https://github.com/10quality/ayuco
Last synced: about 1 year ago
JSON representation
Command-Line interface that can be used to execute commands written in PHP.
- Host: GitHub
- URL: https://github.com/10quality/ayuco
- Owner: 10quality
- License: mit
- Created: 2016-05-11T19:17:44.000Z (about 10 years ago)
- Default Branch: v1.0
- Last Pushed: 2023-02-08T08:57:28.000Z (over 3 years ago)
- Last Synced: 2025-03-23T20:23:09.695Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 43.9 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ayuco
[](https://packagist.org/packages/10quality/ayuco)
[](https://packagist.org/packages/10quality/ayuco)
[](https://packagist.org/packages/10quality/ayuco)
Command-Line interface that can be used to execute commands written in PHP.
**Note:** Commands included in this package (excluding help command) were written for WordPress-MVC.
## Usage
Create a php file that will be called in command-line, [Sample](https://github.com/10quality/ayuco/blob/v1.0/tests/environments/plugin/ayuco), and include the following code lines:
```php
use Ayuco\Listener;
```
Create a listener:
```php
$ayuco = new Listener();
// or without use
$ayuco = new Ayuco\Listener()
```
Register your commands.
```php
$ayuco->register($command1)
->register($command2)
->register(new MyCommand);
```
Start interpreting or listening:
```php
$ayuco->interpret();
```
Use in command line:
```bash
php filename command_key arguments
```
If `filename` is named `ayuco.php` and `command_key` is `clear_cache`, command in *command-line* will be:
```bash
php ayuco.php clear_cache
```
### Arguments and command options
Send arguments right after the `command_key`, for example:
```bash
php ayuco.php cache clear
```
In the example above, `cache` will be the command key and `clear` will be an argument (in order, it will be `$arg[2]`).
Send arguments as command options with the prefix `--`, for example:
```bash
php ayuco.php cache clear --debug --note="Cache clear note"
```
### Create a custom command
Create your own class command by extending from Ayuco base command class:
```php
use Ayuco\Command;
class MyCommand extends Command
{
protected $key = 'command_key';
protected $description = 'My command description.';
public function call($args = [])
{
// TODO command action.
}
}
```
Example for a clear cache command.
```php
use Ayuco\Command;
class ClearCacheCommand extends Command
{
protected $key = 'clear_cache';
protected $description = 'Clears system cache.';
public function call($args = [])
{
Cache::flush(); // Example
}
}
```
Registration in listener would be:
```php
$ayuco->register(new ClearCacheCommand);
```
### Arguments and options
For this command:
```bash
php ayuco.php cache clear
```
The arguments can be accessed like:
```php
use Ayuco\Command;
class CacheCommand extends Command
{
protected $key = 'cache';
public function call($args = [])
{
// ayuco.php
$args[0];
// cache
$args[1];
// clear
$args[2];
}
}
```
For this command:
```bash
php ayuco.php cache clear --debug --note="Cache clear note"
```
The options can be accessed like:
```php
use Ayuco\Command;
class CacheCommand extends Command
{
protected $key = 'cache';
public function call($args = [])
{
// ayuco.php
$args[0];
// cache
$args[1];
// clear
$args[2];
// --debug
$this->options['debug'];
// --note="..."
$this->options['note'];
}
}
```
### Coloring output
Change the coloring of the output printed in the console using class `Ayuco\Coloring` static method `apply()`:
```php
use Ayuco\Coloring;
use Ayuco\Command;
class ColoringCommand extends Command
{
public function call($args = [])
{
$this->_print(Coloring::apply('red', 'Print this message in red.'));
}
}
```
You can read more about coloring [here](https://github.com/php-parallel-lint/PHP-Console-Color).
### Help command
AYUCO automatically will register its own `help` command. This command can be used to display in `command-line` the list of registered commands, use it like:
```bash
php ayuco.php help
```
## Requirements
* PHP >= 5.4
## Coding guidelines
PSR-4.
## LICENSE
The MIT License (MIT)
Copyright (c) 2016 [10Quality](http://www.10quality.com).