/** * 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; }
/** * 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; }