Пример #1
0
 /**
  * Initializes the command just after the input has been validated.
  *
  * This is mainly useful when a lot of commands extends one main command
  * where some things need to be initialized based on the input arguments and options.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     ConsoleUtility::initialize($input, $output);
     // Set default terminal title
     $this->setTerminalTitle(explode(':', $this->getName()));
 }
Пример #2
0
 /**
  * Check if docker exists
  *
  * @throws \CliTools\Exception\StopException
  */
 protected function checkIfDockerExists()
 {
     $dockerPath = \CliTools\Utility\DockerUtility::searchDockerDirectoryRecursive();
     if (!empty($dockerPath)) {
         $this->output->writeln('<info>Running docker containers:</info>');
         // Docker instance found
         $docker = new CommandBuilder('docker', 'ps');
         $docker->executeInteractive();
         $answer = ConsoleUtility::questionYesNo('Are these running containers the right ones?', 'no');
         if (!$answer) {
             throw new \CliTools\Exception\StopException(1);
         }
     }
 }
Пример #3
0
 /**
  * Execute interactive
  *
  * @param array $opts Option array
  * @return $this
  * @throws \Exception
  */
 public function execInteractive(array $opts = null)
 {
     $this->checkCommand();
     ConsoleUtility::verboseWriteln('EXEC::INTERACTIVE', $this->command->build());
     $descriptorSpec = array(0 => array('file', 'php://stdin', 'r'), 1 => array('file', 'php://stdout', 'w'), 2 => array('file', 'php://stderr', 'w'));
     $process = proc_open($this->command->build(), $descriptorSpec, $pipes);
     if (is_resource($process)) {
         if (!empty($opts['startupCallback']) && is_callable($opts['startupCallback'])) {
             $opts['startupCallback']($process);
         }
         do {
             if (is_resource($process)) {
                 $status = proc_get_status($process);
                 if (!empty($status) && !empty($opts['runningCallback']) && is_callable($opts['runningCallback'])) {
                     $opts['runningCallback']($process, $status);
                 }
             } else {
                 break;
             }
             usleep(100 * 1000);
         } while (!empty($status) && is_array($status) && $status['running'] === true);
         if (is_resource($process)) {
             proc_close($process);
         }
         $this->returnCode = $status['exitcode'];
         $this->runFinishers();
         if ($status['signaled'] === true && $status['exitcode'] === -1) {
             // user may hit CTRL+C
             ConsoleUtility::getOutput()->writeln('<comment>Processed stopped by signal</comment>');
         } elseif ($this->strictMode && $this->returnCode !== 0) {
             throw $this->generateException('Process ' . $this->command->getCommand() . ' did not finished successfully');
         }
     } else {
         throw $this->generateException('Process ' . $this->command->getCommand() . ' could not be started');
     }
     return $this;
 }
Пример #4
0
 /**
  * Execute INSERT/DELETE/UPDATE query
  *
  * @param  string $query SQL query
  *
  * @return int
  * @throws \PDOException
  */
 public static function exec($query)
 {
     ConsoleUtility::verboseWriteln('DB::EXEC', $query);
     try {
         $ret = self::getConnection()->exec($query);
     } catch (\PDOException $e) {
         ConsoleUtility::verboseWriteln('DB::EXEC::EXCEPTION', $e);
         throw $e;
     }
     return $ret;
 }