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();
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
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);
$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();