PHP code example of biurad / consolelite

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

    

biurad / consolelite example snippets


#!/usr/bin/env php

// application.php
use BiuradPHP\Toolbox\ConsoleLite\Application;


   // ...
   $application->register(new GenerateCommand());
    

   // ...
   $application->command('hello', 'Enter your name to start', function () {
        $this->writeln('Hello World');
   });

## Console Command Example

### This example is to print out a name without creating a class file




use BiuradPHP\Toolbox\ConsoleLite\Command;

// create a NameCommand.php
class NameCommand extends Command
{
    /** @param string   The Application Name */
    protected $app          =   'Name Command';

    /** @param string   Your Set Command */
    protected $signature    =   'hello {name}';

    /** @param string   Your Command Description */
    protected $description  =   'Enter your name';

    /**
    * The Command Handler
    *
    * @param string $name   The Name input value.
    *
    * @return void
    */
    public function handle($name)
    {
        return $this->writeln("Hello {$name}");
    }
}

#!/usr/bin/env php


use BiuradPHP\Toolbox\ConsoleLite\Application;
use NameCommand;

n->register(new NameCommand);

// 3. Run app
$application->run();

    protected $description = 'Enter a description'; // add a general description.
      

    
    // application.php
    use BiuradPHP\Toolbox\ConsoleLite\Application;

    eral description to the second parameter. */, function () {
        $this->writeln('Hello World');
    });
      

    protected $signature = 'hello'; // add a command.
      

    protected $signature = 'hello {--option} {--anotheroption}'; // the '--' represents an option.
      

    protected $signature = 'hello {--option=} {--anotheroption=}'; // the '=' represents an option has an input.
      

    protected $signature = 'hello {arguement} {anotherarguement}'; // this represents an argument.
      

    protected $signature = 'hello {arguement::Description} {--option::Description} {--option=::Description}'; // the '::' represents a description.
      

    #!/usr/bin/env php
    

    use BiuradPHP\Toolbox\ConsoleLite\Application;
    use BiuradPHP\Toolbox\ConsoleLite\Exception\ConsoleLiteException;
    use BiuradPHP\Toolbox\ConsoleLite\Exception\DeprecatedException;

    on('test')) {
            throw new ConsoleLiteException('Test option not allowed');
        }

        // This throws a deprecated exception.
        if ($this->hasOption('error')) {
            throw new DeprecatedException(['--error', '--replace']);
        }

        $this->block('This is an Exception test');
    });

    $application->run();
   

$this->writeln('Message to output', 'bg_yellow');

$this->writeln('Message to output', 'yellow');

$this->writeln('Message to output', 'italic');

$this->writeln('Message to output', ['bg_yellow', 'green', 'bold']);



/*
 * The Biurad Toolbox ConsoleLite.
 *
 * This is an extensible library used to load classes
 * from namespaces and files just like composer.
 *
 * @see ReadMe.md to know more about how to load your
 * classes via command newLine.
 *
 * @author Divine Niiquaye <[email protected]>
 */

namespace BiuradPHP\Toolbox\ConsoleLite\Commands;

use BiuradPHP\Toolbox\ConsoleLite\Stuble\StubGenerator;

class CommandStub extends StubGenerator
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $signature = 'stuble
    {--command=::Enter a command name of your choice in "coomand:name" pattern.}
    {--force::Forces the class to be overwritten}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new Php File out of a stub';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'Example command';

    /**
     * Set the namespace.
     *
     * @var string
     */
    protected $namespace = 'App\\Console\\';

    /**
     * Set the class.
     *
     * @var string
     */
    protected $class = 'WorldClass';

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getStub()
    {
        return __DIR__.'/../resources/stubs/example.stub';
    }

    /**
     * Replace the class name for the given stub.
     *
     * @param string $stub
     * @param string $name
     *
     * @return string
     */
    protected function replaceClass($stub, $name)
    {
        $stub = parent::replaceClass($stub, $name);

        return str_replace('generate:command', $this->hasOption('command') ?: 'command:name', $stub);
    }
}



namespace GenerateNamespace;

use BiuradPHP\Toolbox\ConsoleLite\Command;

class GenerateClass extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generate:command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        //code...
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //code...
    }
}


use BiuradPHP\Toolbox\ConsoleLite\Application;

tion;

// 2. Register commands
$application->command('hello {name}', 'Enter your name', function($name) {
    $this->writeln("Hello {$name}");
});

// 3. Run app
$application->run();
bash
php console hello --help
bash
php console hello --ansi
bash
php console hello --no-ansi
bash
php vendor/bin/clite compile --config
json
{
    "application": "ConsoleLite Configuration",
    "generated": "2019/06/17 03:41",
    "version": "1.0.0",
    "stuble": {
        "config": {
            "name": "ConsoleLite Stub Generator"
        }
    },
    "compile": {
        "config": {
            "name": "clite.phar",
            "index": "docs/tests/test",
            "compression": 0,
            "signature": null
        },
        "pack": {
            "autoload": "vendor/autoload.php",
            "bin": "docs/tests/test",
            "files": [
                "clite.json",
                "composer.json"
            ],
            "directory": [
                "src/",
                "vendor/"
            ],
            "excludes": [
                "Tests/*",
                "!*.php"
            ]
        },
        "unpack": {
            "extract-to": "unpack",
            "files": null,
            "overwrite": true
        }
    }