PHP code example of fieg / shell

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

    

fieg / shell example snippets


use Fieg\Shell\Shell;
use Fieg\Shell\ShellEvents;

$shell = new Shell();

// handle some commands
$shell->on(ShellEvents::COMMAND, function ($command) use ($shell) {
    switch ($command) {
        case "help":
            $shell->publish('Available commands:');
            $shell->publish('  help   Print this help');
            $shell->publish('  exit   Exit program');
            break;

        case "exit":
            $shell->stop();
            break;

        // echo everything else the user types
        default:
            $shell->publish('echo: ' . $command);
    }
});

// print some info
$shell->publish("This is an interactive shell.");
$shell->publish("Type 'help' for all available commands.");

// start a prompt so we can receive user input
$shell->prompt();

// statements after this are only executed when `$shell->stop()` is called
$shell->run();

echo "Bye!" . PHP_EOL;

$shell = new HistoryDecorator(new Shell());