Beispiel #1
0
 /**
  * Handle the run shell action
  * @return ShellResult
  */
 public function doShell()
 {
     // $shell is derived from RunResult
     $shell = new Shell();
     while (!$shell->isEOF()) {
         if ($shell->isFail()) {
             break;
         }
         $input = $shell->readInput();
         if ($input === FALSE) {
             break;
         }
         // Available shell commands (for help sreen)
         $shell_commands = array('dump', 'exit', 'help');
         // Interpret shell keywords
         switch ($input) {
             case 'exit':
                 break 2;
             case 'dump':
                 $this->stdout(print_r($this->getMemory()->getData(), true));
                 break;
             case 'help':
                 $extension_manager = $this->getExtensionManager();
                 $exports = $extension_manager->exports();
                 $this->stdout(PHP_EOL);
                 $this->stdout(str_pad(' Commands:', 13) . join(', ', $shell_commands) . PHP_EOL);
                 $this->stdout(str_pad(' Keywords:', 13) . join(', ', $this->getLanguageKeywords()) . PHP_EOL);
                 $this->stdout(str_pad(' Functions:', 13) . join(', ', $exports) . PHP_EOL);
                 $this->stdout(PHP_EOL);
                 break;
             default:
                 // Assume is code
                 $this->setCode($input);
                 $result = $this->doRun();
                 // TODO: Finished this
                 // dd($result);
                 // $this->stdout()
                 // Handle printing errors
                 if ($result->isFail()) {
                     foreach ($result->getErrors() as $error) {
                         $this->stderr($this->outputFormatErrorMessage($error));
                     }
                 }
                 break;
         }
         // TODO: Provide interface for setting position :/
         $this->line++;
         $this->column = 0;
     }
     $shell->setData($this->getMemory()->getData());
     return $shell;
 }