Exemple #1
0
 /**
  * Prints a message to output.
  *
  * @param string $Message
  * @param \BLW\Type\Command\IInput $Input
  *            Input object to read data from.
  * @param \BLW\Type\Command\IOutput $Output
  *            Output object to write data to.
  * @param integer $flags
  *            Flags used to run commands.
  * @return int Exit code (0)
  */
 private function _die($Message, IInput $Input, IOutput $Output, $flags)
 {
     // Cron already running
     $Command = new CallbackCommand(function ($Input, $Output) use($Message) {
         // Output notice
         $Output->write($Message);
         // Done
         return 0;
     }, new GenericConfig(array('Timeout' => 10)));
     return $Command->run($Input, $Output, $flags);
 }
Exemple #2
0
 /**
  * @covers ::doRun
  */
 public function test_doRun()
 {
     $this->assertEquals(-1, $this->Command->doRun($this->Input, $this->Output), 'CallbackCommand::doRun() returned an invalid result');
     $this->assertEquals(1, $this->Called, 'CallbackCommand::doRun() Failed to call callback');
 }
Exemple #3
0
 /**
  * Runs the application.
  *
  * @param callback $Callback
  *            Callback to call during running.
  * @param \BLW\Type\Command\IInput $Input
  *            Command input.
  * @param \BLW\Type\Command\IOutput $Output
  *            Command output.
  * @return integer <code>NULL</code> or 0 if everything went fine. Error code otherwise.
  */
 public static function run($Callback, IInput $Input = null, IOutput $Output = null)
 {
     // Input and output
     $Input = $Input ?: new StdInput();
     $Output = $Output ?: new StdOutput();
     $Start = microtime(true);
     // Run console
     self::$Logger->info(sprintf('Started console app. %s.', date('c')));
     $Command = new CallbackCommand($Callback, new Config\Generic(array('Description' => 'BLW library console command', 'Timeout' => 10, 'Logger' => self::$Logger)), self::$Mediator, 'build');
     $return = $Command->run($Input, $Output);
     // Done
     self::$Logger->info(sprintf('Finished console app. Total time: %01.2f seconds.', microtime(true) - $Start));
     return $return;
 }