本文整理匯總了PHP中Symfony\Component\Console\Output\ConsoleOutput::write方法的典型用法代碼示例。如果您正苦於以下問題:PHP ConsoleOutput::write方法的具體用法?PHP ConsoleOutput::write怎麽用?PHP ConsoleOutput::write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Output\ConsoleOutput
的用法示例。
在下文中一共展示了ConsoleOutput::write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: writeln
public function writeln($sprintf)
{
$arguments = func_get_args();
$arguments[0] .= PHP_EOL;
$message = call_user_func_array("sprintf", $arguments);
$this->laravelConsoleOutput->write($message);
}
示例2: readline
/**
* @return string
*/
protected function readline()
{
$this->output->write($this->getPrompt());
$line = fgets(STDIN, 1024);
$line = false === $line || '' === $line ? false : rtrim($line);
return $line;
}
示例3: output
/**
* 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);
}
示例4: output
/**
* 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
}
示例5: write
/**
* 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>";
}
}
}
示例6: execute_commands
/**
* @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;
}
示例7: write
/**
* 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);
}
示例8: createConsoleOutput
/**
* @return OutputWriter
*/
public static function createConsoleOutput()
{
$output = new ConsoleOutput();
return new OutputWriter(function ($message) use($output) {
$output->write($message, TRUE);
});
}
示例9: write
/**
* {@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);
}
示例10: write
/**
* 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);
}
示例11: execute_commands
/**
* @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("");
}
}
示例12: readline
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;
}
示例13: write
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);
}
示例14: terminate
/**
* @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('');
// }
}
示例15: createDatabase
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 . '.');
}
}