PHP code example of zein / console

1. Go to this page and download the library: Download zein/console 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/ */

    

zein / console example snippets



namespace Commands;
use Zein\Console\Command\Contract;

class Make extends Contract
{
    protected array $signatures = [
        'make:plugin' => ['description' => 'Make a plugin', 'input' => '{pluginname}']
    ];
    
    protected array $commandOptions = [
        '--type' => 'Set plugin type'
    ];

    public function handle()
    {
        // Retrieve all option
        $option = $this->option();

        // Retrieve single option
        $option = $this->option('type');

        // Retrive all argument
        $argument = $this->argument();

        // Retrieve single argument
        $argument = $this->argument('type');

        // running code here
    }
}


namespace App;
use Zein\Console\{Console,Argument,Output\Output};

class AppConsole extends Console
{
    private object $argument;

    public function __construct()
    {
        $this->argument = new Argument;
        $this->argument->strict = false;
        $this->argument->fetch();    
    }

    public function run()
    {
        if (!$this->argument->get())
        {
            Output::help($this->commandClass);
        }

        $Parameter = $this->argument->getParameter();
        $Option = $this->argument->getOption();

        // Run command
        $Command = $this->{$this->seperateCommand($Parameter[0])};
        $CommandInstance = new $Command($Option, $Parameter);

        $CommandInstance->handle();
    }
}



use App\AppConsole;

le;
$AppConsole->register([
    'make' => \Commands\Make::class,
]);

$AppConsole->run();


app
---- AppConsole.php
commands
---- Make.php
app.php
vendor
BASH
php app.php make:plugin dummies --type=report