Bugfixes and improvements to shell and context

This commit is contained in:
2016-11-02 13:53:56 +01:00
parent a2c1148c52
commit fe27eeb4a3
2 changed files with 29 additions and 1 deletions

View File

@ -12,6 +12,9 @@ class Context
protected $data = [];
protected $parent;
protected $shell;
public function __construct($name=null, array $data=[])
{
@ -20,6 +23,28 @@ class Context
$this->configure();
}
public function setParent(Context $parent=null)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
public function getRoot()
{
if (!$this->parent) {
return $this;
}
$node = $this;
while ($parent = $node->getParent()) {
$node = $parent;
}
return $parent;
}
protected function configure()
{
// Override this to do setup stuff
@ -52,6 +77,7 @@ class Context
{
$this->commands[$command] = $handler;
$this->commandInfo[$command] = $info;
ksort($this->commands);
}
public function setCommandHelp($command, $help)