dev-master
9999999-devInteractive shell (cli) component for PHP
MIT
The Requires
The Development Requires
cli shell interactive
1.0
1.0.0.0Interactive shell (cli) component for PHP
MIT
The Requires
The Development Requires
cli shell interactive
Wallogit.com
2017 © Pedro Peláez
Interactive shell (cli) component for PHP
Interactive shell (cli) component for PHP, (*1)
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;
This library also comes with a history support. With this you can use the up and down arrows to browse through the recently typed commands. To enable the history support, just wrap the Shell class in a HistoryDecorator:, (*3)
$shell = new HistoryDecorator(new Shell());
You can also type the command "history" to see a list of all recently typed commands., (*4)
Interactive shell (cli) component for PHP
MIT
cli shell interactive
Interactive shell (cli) component for PHP
MIT
cli shell interactive