Improvements
This commit is contained in:
		@@ -1,46 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
require_once __DIR__."/../vendor/autoload.php";
 | 
			
		||||
 | 
			
		||||
use NoccyLabs\Shell\Shell;
 | 
			
		||||
 | 
			
		||||
class MyShell extends Shell
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    protected $params;
 | 
			
		||||
 | 
			
		||||
    protected function setParam($key, $value=null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->params[$key] = $value;
 | 
			
		||||
        $this->writeln(" ** {$key} = {$value}");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function configure(array $config)
 | 
			
		||||
    {
 | 
			
		||||
        $this->addCommand("set", [$this,"setParam"]);
 | 
			
		||||
        $this->addCommand("exit", [$this,"stop"]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function getPrompt()
 | 
			
		||||
    {
 | 
			
		||||
        return "flinger: ";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 onInput($buffer)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$myShell = new MyShell();
 | 
			
		||||
$myShell->run();
 | 
			
		||||
							
								
								
									
										58
									
								
								examples/simple.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								examples/simple.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
require_once __DIR__."/../vendor/autoload.php";
 | 
			
		||||
 | 
			
		||||
use NoccyLabs\Shell\Shell;
 | 
			
		||||
use NoccyLabs\Shell\Command;
 | 
			
		||||
 | 
			
		||||
class MyCommand extends Command
 | 
			
		||||
{
 | 
			
		||||
    public function getName()
 | 
			
		||||
    {
 | 
			
		||||
        return "mycommand";
 | 
			
		||||
    }
 | 
			
		||||
    public function execute()
 | 
			
		||||
    {
 | 
			
		||||
        $this->writeln("Executing command");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class MyShell extends Shell
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    protected $seq = 0;
 | 
			
		||||
 | 
			
		||||
    protected function configure(array $config)
 | 
			
		||||
    {
 | 
			
		||||
        $this->addCommand("hello", function () {
 | 
			
		||||
            echo "world\n\rthis\n\ris\n\ra\ntest\n\r";
 | 
			
		||||
        });
 | 
			
		||||
        $this->addCommand(new MyCommand());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function getPrompt()
 | 
			
		||||
    {
 | 
			
		||||
        return "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++;
 | 
			
		||||
        parent::onCommand($buffer);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$myShell = new MyShell();
 | 
			
		||||
$myShell->run();
 | 
			
		||||
echo "Exiting\n";
 | 
			
		||||
		Reference in New Issue
	
	Block a user