Example #1
0
 public function execute(Context $context)
 {
     if ($context->getCurrentCommand() !== 'begin') {
         throw new \RuntimeException('illegal command ' . $context->getCurrentCommand());
     }
     $command_list = new CommandListCommand();
     $command_list->execute($context->next());
 }
Example #2
0
 public function execute(Context $context)
 {
     while (true) {
         $current_command = $context->getCurrentCommand();
         if (is_null($current_command)) {
             throw new \RuntimeException('"end" not found ');
         } elseif ($current_command === 'end') {
             break;
         } else {
             $command = new CommandCommand();
             $command->execute($context);
         }
         $context->next();
     }
 }
Example #3
0
 public function execute(Context $context)
 {
     $current_command = $context->getCurrentCommand();
     if ($current_command === 'diskspace') {
         $path = './';
         $free_size = disk_free_space('./');
         $max_size = disk_total_space('./');
         $ratio = $free_size / $max_size * 100;
         echo sprintf('Disk Free : %5.1dMB (%3d%%)%s', $free_size / 1024 / 1024, $ratio, PHP_EOL);
     } elseif ($current_command === 'date') {
         echo date('Y/m/d H:i:s') . PHP_EOL;
     } elseif ($current_command === 'line') {
         echo '--------------------' . PHP_EOL;
     } else {
         throw new \RuntimeException('invalid command [' . $current_command . ']');
     }
 }