PHP code example of marcus-campos / simple-php-cli

1. Go to this page and download the library: Download marcus-campos/simple-php-cli 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/ */

    

marcus-campos / simple-php-cli example snippets




namespace App\Commands;


use Console\BaseCommand;
use Console\Contracts\ConsoleContract;

class ClassName extends BaseCommand implements ConsoleContract
{
    public function execute()
    {
        //Get the argument in the first position
        $argument = $this->util->args()['arguments'][0];
        //Prints a line in the console
        $this->util->output()->writeLn('Hello world!', 'green');
        //Prints a line in the console containing the value passed in the parameter
        $this->util->output()->writeLn('My param ' . $argument, 'green');
    }
}

    private $commands = [
           ...
            'new:command' => [
                'action' => MyCommand::class.'@execute',
                'params' => [
                               'param1',
                               'param2',
                               'param3',
                               ...
                           ],
                'description' => 'My command description',
            ],
           ...
        ];

    private $commands = [
           ...
            'sympla' => [
                'action' => SymplaCommand::class.'@inspire',
                'description' => 'Descrição do meu outro comando',
            ],
           ...
        ];
bash 
composer create-project marcus-campos/simple-php-cli MyCliAppName
bash
    php run help