PHP code example of 10quality / ayuco

1. Go to this page and download the library: Download 10quality/ayuco library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

10quality / ayuco example snippets


use Ayuco\Listener;

$ayuco = new Listener();

// or without use
$ayuco = new Ayuco\Listener()

$ayuco->register($command1)
    ->register($command2)
    ->register(new MyCommand);

$ayuco->interpret();

use Ayuco\Command;

class MyCommand extends Command
{
    protected $key = 'command_key';

    protected $description = 'My command description.';

    public function call($args = [])
    {
        // TODO command action.
    }
}

use Ayuco\Command;

class ClearCacheCommand extends Command
{
    protected $key = 'clear_cache';

    protected $description = 'Clears system cache.';

    public function call($args = [])
    {
        Cache::flush(); // Example
    }
}

$ayuco->register(new ClearCacheCommand);

use Ayuco\Command;

class CacheCommand extends Command
{
    protected $key = 'cache';

    public function call($args = [])
    {
        // ayuco.php
        $args[0];

        // cache
        $args[1];

        // clear
        $args[2];
    }
}

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'];
    }
}

use Ayuco\Coloring;
use Ayuco\Command;

class ColoringCommand extends Command
{
    public function call($args = [])
    {
        $this->_print(Coloring::apply('red', 'Print this message in red.'));
    }
}
bash
php ayuco.php clear_cache
bash
php ayuco.php cache clear 
bash
php ayuco.php cache clear --debug --note="Cache clear note"
bash
php ayuco.php cache clear 
bash
php ayuco.php cache clear --debug --note="Cache clear note"
bash
php ayuco.php help