PHP code example of faslatam / consolekit

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

    

faslatam / consolekit example snippets




class HelloCommand extends ConsoleKit\Command {
  function execute(array $args, array $options = []) {
    $this->writeln('hello world!', ConsoleKit\Colors::GREEN);
  }
}

$console = new ConsoleKit\Console();
$console->addCommand('HelloCommand');
$console->run();

set_

$args = ['arg1', 'arg2', '--any text'];
$options = [
  'a' => true,
  'b' => true,
  'c' => true,
  'longopt' => true,
  'key' => 'value'
];

function my_command($args, $opts, $console) {
  $console->writeln("hello world!");
}

class MyCommand extends ConsoleKit\Command {
  function execute(array $args, array $opts) {
      $this->writeln("hello world!");
  }
}

$console = new ConsoleKit\Console();
$console->addCommand('my_command'); // the my_command function
$console->addCommand('MyCommand'); // the MyCommand class
$console->addCommand(function() { echo 'hello!'; }, 'hello'); // using a closure
// or:
$console->addCommand('hello', function() { echo 'hello!'; }); // alternative when using a closure

$console->run();
$console->run(array('custom arg1', 'custom arg2')); // overrides $_SERVER['argv']

echo Colors::colorize('my red text', Colors::RED);
echo Colors::colorize('my red text', 'red');

echo Colors::colorize('my red bold text', Colors::RED | Colors::BOLD);
echo Colors::colorize('my red bold text', 'red+bold');

echo Colors::colorize('my red text over yellow background', Colors::RED, Colors::YELLOW);

$formater = new ConsoleKit\TextFormater(array('quote' => ' > '));
echo $formater->format("hello!");
// produces: " > hello"

$dialog = new ConsoleKit\Widgets\Dialog($console);
$name = $dialog->ask('What is your name?');

if ($dialog->confirm('Are you sure?')) {
  $console->writeln("hello $name");
}

$box = new ConsoleKit\Widgets\Box($console, 'my text');
$box->write();

$total = 100;
$progress = new ConsoleKit\Widgets\ProgressBar($console, $total);

for ($i = 0; $i < $total; $i++) {
  $progress->incr();
  usleep(10000);
}

$progress->stop();
bash
php cli.php hello
bash
php myscript.php help