public function writeln($sprintf) { $arguments = func_get_args(); $arguments[0] .= PHP_EOL; $message = call_user_func_array("sprintf", $arguments); $this->laravelConsoleOutput->write($message); }
/** * @return string */ protected function readline() { $this->output->write($this->getPrompt()); $line = fgets(STDIN, 1024); $line = false === $line || '' === $line ? false : rtrim($line); return $line; }
/** * Outputs specified text to the console window * You can specify arguments that will be passed to the text via sprintf * @see http://www.php.net/sprintf * * @param string $text Text to output * @param array $arguments Optional arguments to use for sprintf * @return void */ public function output($text, array $arguments = array()) { if ($arguments !== array()) { $text = vsprintf($text, $arguments); } $this->output->write($text); }
/** * Prints a message to console * * @param $message * @param int $tabs * @param int $newLine */ public function output($message, $tabs = 1, $newLine = 1) { //Auto logs to File $this->log(strip_tags($message)); $this->consoleOutput->write(str_repeat("\t", $tabs)); $this->consoleOutput->write($message); // Writes Message to console $this->consoleOutput->write(str_repeat(PHP_EOL, $newLine)); // New Lines }
/** * Outputs a string to the cli. If you send an array it will implode them * with a line break. * * @param string|array $text the text to output, or array of lines * @param bool $newline */ public static function write($text = '', $newline = false) { if (is_array($text)) { foreach ($text as $line) { CLI::write($line); } } else { if (PHP_SAPI == 'cli') { static::$output->write($text, $newline); } else { echo "<h4>{$text}</h4>"; } } }
/** * @param $commands * @param \Symfony\Component\Console\Output\ConsoleOutput $output * * @return boolean */ function execute_commands($commands, $output) { foreach ($commands as $command) { list($command, $message, $allowFailure) = $command; $output->write(sprintf(' - %\'.-70s', $message)); $return = array(); if (is_callable($command)) { $success = $command($output); } else { $p = new \Symfony\Component\Process\Process($command); $p->setTimeout(null); $p->run(function ($type, $data) use(&$return) { $return[] = $data; }); $success = $p->isSuccessful(); } if (!$success && !$allowFailure) { $output->writeln('<error>KO</error>'); $output->writeln(sprintf('<error>Fail to run: %s</error>', is_callable($command) ? '[closure]' : $command)); foreach ($return as $data) { $output->write($data, false, OutputInterface::OUTPUT_RAW); } $output->writeln("If the error is coming from the sandbox,"); $output->writeln("please report the issue to https://github.com/sonata-project/sandbox/issues"); return false; } else { if (!$success) { $output->writeln("<info>!!</info>"); } else { $output->writeln("<info>OK</info>"); } } } return true; }
/** * Write an entry to the console and to the provided logger. * * @param array|string $message * @param bool $newline * @param int $type * * @return void */ public function write($message, $newline = false, $type = 0) { if ($this->getLogger()) { $this->getLogger()->info($this->getFormatter()->format(strip_tags($message))); } parent::write($message, $newline, $type); }
/** * @return OutputWriter */ public static function createConsoleOutput() { $output = new ConsoleOutput(); return new OutputWriter(function ($message) use($output) { $output->write($message, TRUE); }); }
/** * {@inheritdoc} */ public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL) { $messages = (array) $messages; foreach ($messages as $message) { $this->logger->log(200, strip_tags($message)); } reset($messages); parent::write($messages, $newline, $options); }
/** * Write an entry to the console and to the provided logger. * * @param array|string $message * @param bool $newline * @param int $type * * @return void */ public function write($message, $newline = false, $type = 0) { $messages = (array) $message; if ($this->getLogger()) { foreach ($messages as $message) { $this->getLogger()->info($this->getFormatter()->format(strip_tags($message))); } } parent::write($messages, $newline, $type); }
/** * @param $commands * @param \Symfony\Component\Console\Output\ConsoleOutput $output * @return void */ function execute_commands($commands, $output) { foreach ($commands as $command) { $output->writeln(sprintf('<info>Executing : </info> %s', $command)); $p = new \Symfony\Component\Process\Process($command); $exit = $p->run(function ($type, $data) use($output) { $output->write($data); }); $output->writeln(""); } }
private function readline($prompt) { if (function_exists('readline')) { $line = readline($prompt); } else { $this->output->write($prompt); $line = fgets(STDIN, 1024); $line = !$line && strlen($line) == 0 ? false : rtrim($line); } return $line; }
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL) { $messagesToLog = (array) $messages; foreach ($messagesToLog as $message) { if (strlen($message) === 0) { continue; } //$message = strip_tags($this->getFormatter()->format($message)); $message = strip_tags($message); $this->logger->info($message); } parent::write($messages, $newline, $options); }
/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, true); $output->write(str_pad("\r", 80, " ")); $output->writeln(''); // score $score = $collection->getScore(); // if($score) { foreach ($score->all() as $name => $value) { $output->writeln(sprintf('%s %s', str_pad($name, 35, '.'), str_pad($value, 5, ' ', STR_PAD_LEFT) . ' / ' . Scoring::MAX)); } $output->writeln(''); // } }
private static function createDatabase(Application $application) { $output = new ConsoleOutput(); self::executeCommand($application, 'doctrine:database:drop', array('--force' => true)); $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection(); if ($connection->isConnected()) { $connection->close(); } self::executeCommand($application, 'doctrine:database:create'); $output->write('Drop database...'); $dropDatabase = self::executeCommand($application, 'doctrine:schema:drop', array('--force' => true)); if (0 === $dropDatabase) { $output->writeln(' Ok.'); } else { $output->writeln('Error: ' . $dropDatabase . '.'); } $output->write('Create database...'); $createDatabase = self::executeCommand($application, 'doctrine:schema:create'); if (0 === $createDatabase) { $output->writeln(' Ok.'); } else { $output->writeln('Error: ' . $createDatabase . '.'); } $loadFixturesOptions = array('-n' => true); $fixtures = static::getFixtures(); if (count($fixtures)) { $loadFixturesOptions['--fixtures'] = $fixtures; } $output->write('Load fixtures...'); $loadFixtures = self::executeCommand($application, 'wealthbot:fixtures:load', $loadFixturesOptions); if (0 === $loadFixtures) { $output->writeln(' Ok.'); } else { $output->writeln('Error: ' . $loadFixtures . '.'); } }
/** * @param $commands * @param \Symfony\Component\Console\Output\ConsoleOutput $output * * @return boolean */ function execute_commands($commands, $output) { foreach ($commands as $command) { $output->writeln(sprintf('<info>Executing : </info> %s', $command)); $p = new \Symfony\Component\Process\Process($command); $p->setTimeout(null); $p->run(function ($type, $data) use($output) { $output->write($data); }); if (!$p->isSuccessful()) { return false; } $output->writeln(""); } return true; }
public function onStatusChange(GameStatusEvent $event) { $output = new ConsoleOutput(); $game = $event->getGame(); $status = $event->getStatus(); $output->write($game->getFileName() . "\t\t:: "); switch ($status) { case GameStatusEvent::GAME_MD5_NOT_FOUND: $output->writeln("<error>MD5 not found, try again later</error>"); break; case GameStatusEvent::GAME_STREAMING: if ($game->getShift() != false) { $output->writeln("<fg=cyan>continue streaming from " . $game->getShift() . "</>"); } else { $output->writeln("<fg=cyan>start game streaming...</>"); } break; case GameStatusEvent::GAME_FILE_EXISTS: $output->writeln("<info>Game file already exists</info>"); break; case GameStatusEvent::FILE_NOT_EXISTS: $output->writeln("<error>File not exists.</error>"); break; case GameStatusEvent::GAME_NOT_STARTED: $timeKyiv = new \DateTime($game->getDateTime(), new \DateTimeZone("America/New_York")); $timeKyiv->setTimezone(new \DateTimeZone("Europe/Kiev")); $output->writeln(sprintf("<fg=cyan>Game will start at %s</>", $timeKyiv->format("Y-m-d H:i"))); break; case GameStatusEvent::GAME_IS_RUNNING: $output->writeln("<fg=cyan>Game is still running LIVE</>"); break; case GameStatusEvent::GAME_URL_EXISTS: $output->writeln("<info>Game URL already exists</info>"); break; case GameStatusEvent::GAME_URL_FOUND: $output->writeln("<info>Game URL found</info>"); break; case GameStatusEvent::GAME_ADD_LOGO: $output->writeln("<fg=cyan>start adding logo to the file...</>"); break; case GameStatusEvent::GAME_URL_NOT_FOUND: default: $output->writeln("<error>Game URL NOT FOUND</error>"); break; } }
/** * * @return ClassesBuilder */ protected function writeClasses($force = false) { $n = 0; $classesBuffer = new TagProviderBuilder('', 'TagProvider', array(), '\\Pimple'); $buffer = array(); foreach ($this->classes as $class) { try { $class->write($force); if (strpos($class->getNamespace(), 'PHPExiftool\\Driver\\Tag') === 0) { if (!isset($buffer[$class->getProperty('GroupName')])) { $buffer[$class->getProperty('GroupName')] = array(); } $buffer[$class->getProperty('GroupName')][$class->getProperty('Name')] = $class->getNamespace() . '\\' . $class->getClassname(); } $this->output->write(sprintf("\rwriting class #%5d", $n++)); } catch (\Exception $e) { $this->output->writeln(sprintf("\n<error>Error while writing class %s</error>", $class->getPathfile())); } } $classesBuffer->setClasses($buffer); $classesBuffer->write(true); $this->output->writeln(''); return $this; }
protected function _index($service, $index, $type, $tdata, $id, OutputInterface $output = null) { if (!$output) { $output = new ConsoleOutput(); } $output->writeln(" Update element '{$id}' of type: '{$type}'"); // $atonce = UtilArray::cascadeGet($tdata, 'mapping.maxresults'); // $useidfrom = UtilArray::cascadeGet($tdata, 'mapping.useidfrom'); $setupquerybuilder = UtilArray::cascadeGet($tdata, 'mapping.setupquerybuilder'); $findbyid = UtilArray::cascadeGet($tdata, 'mapping.findbyid'); $transform = UtilArray::cascadeGet($tdata, 'mapping.transformermethod'); /* @var $qb QueryBuilder */ $qb = call_user_func(array($service, $findbyid), $id); $r = $this->dbal->fetchAssoc($qb->getSQL()); if ($transform) { $r = call_user_func(array($service, $transform), $r); } $row = array(); foreach ($tdata['properties'] as $name => &$f) { $row[$name] = UtilNested::get($r, $f['mapping']['field']); } $output->write(" Update: {$id}\r"); $result = $this->api('PUT', "/{$index}/{$type}/{$id}", $row); $output->writeln(PrettyJson::encode($result)); }
/** * Writes a console message * * @author Art <*****@*****.**> * * @param array|string $messages The message or array of messages * @param bool $newline Whether to insert a newline after the message(s) * @param int $type Output type * * @return self */ public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL) { parent::write($messages, $newline, $type); return $this; }
/** * Writes a message to the output. * * Optionally, pass `$type | self::NUMBER_LINES` as the $type parameter to * number the lines of output. * * @throws \InvalidArgumentException When unknown output type is given * * @param string|array $messages The message as an array of lines or a single string * @param bool $newline Whether to add a newline or not * @param int $type The type of output */ public function write($messages, $newline = false, $type = 0) { if ($this->getVerbosity() === self::VERBOSITY_QUIET) { return; } $messages = (array) $messages; if ($type & self::NUMBER_LINES) { $pad = strlen((string) count($messages)); $template = $this->isDecorated() ? "<aside>%{$pad}s</aside>: %s" : "%{$pad}s: %s"; if ($type & self::OUTPUT_RAW) { $messages = array_map(array('Symfony\\Component\\Console\\Formatter\\OutputFormatter', 'escape'), $messages); } foreach ($messages as $i => $line) { $messages[$i] = sprintf($template, $i, $line); } // clean this up for super. $type = $type & ~self::NUMBER_LINES & ~self::OUTPUT_RAW; } parent::write($messages, $newline, $type); }
/** * Remote fork/branch tests * * @return boolean */ private function runTestsFork() { $prDetails = $this->git->getPr($this->prNum); $remoteName = 'bolt-fork-' . $prDetails->head->repo->id; $remoteUrl = $prDetails->head->repo->clone_url; $remoteBranch = $prDetails->head->ref; // Get PRs git remote and fetch all branches if ($this->git->addRemote($remoteName, $remoteUrl) === 0) { $this->git->fetchAll(); } else { $this->output->write('<error>Failed to add the remote</error>', true); $this->git->delRemote($remoteName); return false; } // Checkout the PRs branch if ($this->git->checkoutBranch($remoteBranch, $remoteName) === 0) { if ($this->comparator->runPhpUnitCoverage($this->afterFile, $this->test) !== 0) { $this->output->write('<error>Failed to run PHPUnit test against PR branch</error>', true); } $result = true; } else { $result = false; $this->output->write('<error>Failed to checkout remote branch</error>', true); } // Clean up $this->git->checkoutBranch('master'); $this->git->removeBranch($remoteBranch); $this->git->delRemote($remoteName); return $result; }