61 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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;
 | 
						|
 | 
						|
    public function __construct()
 | 
						|
    {
 | 
						|
        $context = new MyContext();
 | 
						|
        $this->pushContext($context);
 | 
						|
        $this->updatePrompt();
 | 
						|
 | 
						|
        $t1 = $this->addTimer(5000, function () {
 | 
						|
            echo "5 seconds\n";
 | 
						|
        });
 | 
						|
        $app = $this;
 | 
						|
        $t2 = $this->addTimer(15000, function () use ($t1, $app) {
 | 
						|
            echo "Removing timers...\n";
 | 
						|
            $app->removeTimer($t1);
 | 
						|
        });
 | 
						|
        
 | 
						|
    }
 | 
						|
    
 | 
						|
    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";
 |