php-shell/examples/timers.php

61 lines
1.1 KiB
PHP
Raw Normal View History

2016-11-02 13:22:53 +00:00
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Shell\Shell;
use NoccyLabs\Shell\Command;
use NoccyLabs\Shell\Context;
class MyContext extends Context
{
/**
* @command testme
* @args
* @help Useful test!
*/
public function test()
{
}
}
class MyShell extends Shell
{
protected $seq = 0;
2017-01-23 23:49:13 +00:00
public function __construct()
2016-11-02 13:22:53 +00:00
{
$context = new MyContext();
$this->pushContext($context);
$this->updatePrompt();
2017-01-22 22:22:13 +00:00
$t1 = $this->addTimer(5000, function () {
2016-11-02 13:22:53 +00:00
echo "5 seconds\n";
});
2017-01-22 22:22:13 +00:00
$app = $this;
$t2 = $this->addTimer(15000, function () use ($t1, $app) {
echo "Removing timers...\n";
$app->removeTimer($t1);
});
2016-11-02 13:22:53 +00:00
}
protected function updatePrompt()
{
$this->setPrompt("test[{$this->seq}]: ");
}
protected function onCommand($buffer)
{
$this->seq++;
$this->updatePrompt();
parent::onCommand($buffer);
}
}
$myShell = new MyShell();
$myShell->run();
echo "Exiting\n";