58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once __DIR__."/../vendor/autoload.php";
|
|
|
|
use NoccyLabs\Shell\Shell;
|
|
use NoccyLabs\Shell\Command;
|
|
|
|
class MyCommand extends Command
|
|
{
|
|
public function execute()
|
|
{
|
|
echo "Executing command";
|
|
}
|
|
}
|
|
|
|
class MyShell extends Shell
|
|
{
|
|
|
|
protected $seq = 0;
|
|
|
|
protected function configure()
|
|
{
|
|
$context = $this->createContext();
|
|
$context->addCommand("hello", function () {
|
|
echo "world\nthis\nis\na\ntest\n";
|
|
});
|
|
$context->addCommand("mycommand", new MyCommand());
|
|
$this->updatePrompt();
|
|
}
|
|
|
|
protected function updatePrompt()
|
|
{
|
|
$this->setPrompt("test[{$this->seq}]: ");
|
|
}
|
|
|
|
protected function onUpdate()
|
|
{
|
|
static $lt;
|
|
$t = floor(microtime(true));
|
|
if ($t > $lt) {
|
|
$lt = $t + 5;
|
|
echo date("Y-m-d h:i:s")."\n";
|
|
}
|
|
}
|
|
|
|
protected function onCommand($buffer)
|
|
{
|
|
$this->seq++;
|
|
$this->updatePrompt();
|
|
parent::onCommand($buffer);
|
|
}
|
|
|
|
}
|
|
|
|
$myShell = new MyShell();
|
|
$myShell->run();
|
|
echo "Exiting\n";
|