/** * @param Context $context * * @return CommandInterface * @throws \Exception */ public static function run(Context $context) { Console::getInstance()->backgroundLightGreen()->white()->out("Running <bold>{$context->command}</bold> command"); $commandClass = "\\minion\\commands\\" . ucwords(strtolower($context->command)) . "Command"; if (class_exists($commandClass) === false) { throw new \Exception("Unknown command {$context->command}"); } /** @var CommandInterface $command */ $command = new $commandClass(); // Check for run method if (method_exists($command, 'run') === false) { throw new \Exception("Command {$context->command} run method does not exist"); } return $command->run($context); }
public function run(array $arguments) { // read version from command line $this->version = file_get_contents(__DIR__ . '/../VERSION'); $startTime = microtime(true); // Build the environment object. This object gets passed all the way through the stack. try { Console::getInstance()->backgroundDarkGray()->brightBlue("# minion // v{$this->version} #"); $this->context = new Context($arguments); Command::run($this->context); } catch (\Exception $e) { Console::getInstance()->backgroundRed()->white("[ERROR] {$e->getMessage()}"); //echo("[ERROR] {$e->getMessage()}\n"); } Console::getInstance()->backgroundDarkGray()->brightBlue("# minion completed #"); //Console::getInstance()->lightGray('time='.round(microtime(true) - $startTime, 3).'s'); }
public function execute($command, $showCommand = false, $showResponse = false) { if ($showCommand) { Console::getInstance()->inline("\tExecuting <bold>{$command}</bold> "); } $response = system($command, $status); if ($status) { Console::getInstance()->backgroundRed()->brightWhite("FAILED!"); throw new \Exception($response); } if ($showCommand) { Console::getInstance()->bold()->out('OK'); } if ($showResponse) { Console::getInstance()->backgroundWhite()->blue(trim($response)); } return $response; }
/** * @param $task * @param Context $context * @param Environment $environment * @param ConnectionInterface|null $connection * * @return mixed * @throws \Exception */ public static function run($task, Context $context, Environment $environment, ConnectionInterface $connection = null) { Console::getInstance()->green()->out("* Running <bold><white>" . trim($task) . "</white></bold> task"); // Normalize task class name $task = ucfirst(strtolower(trim($task))); // What task are we running? $taskClass = "\\minion\\tasks\\{$task}Task"; if (class_exists($taskClass) == false) { throw new \Exception("Task {$taskClass} was not found."); } /** @var TaskInterface $task */ $task = new $taskClass(); // Check for run method if (method_exists($task, 'run') === false) { throw new \Exception("Task {$task} run method does not exist"); } return $task->run($context, $environment, $connection); }
public function say($message) { Console::getInstance()->comment($message); }