当前位置: 首页>>代码示例>>PHP>>正文


PHP Helper\Helper类代码示例

本文整理汇总了PHP中Symfony\Component\Console\Helper\Helper的典型用法代码示例。如果您正苦于以下问题:PHP Helper类的具体用法?PHP Helper怎么用?PHP Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: block

 /**
  * Formats a message as a block of text.
  *
  * @param string|array $messages The message to write in the block
  * @param string|null $type The block type (added in [] on first line)
  * @param string|null $style The style to apply to the whole block
  * @param string $prefix The prefix for the block
  * @param bool $padding Whether to add vertical padding
  */
 public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false)
 {
     $this->autoPrependBlock();
     $messages = is_array($messages) ? array_values($messages) : array($messages);
     $lines = array();
     // add type
     if (null !== $type) {
         $messages[0] = sprintf('[%s] %s', $type, $messages[0]);
     }
     // wrap and add newlines for each element
     foreach ($messages as $key => $message) {
         $message = OutputFormatter::escape($message);
         $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix), PHP_EOL, true)));
         if (count($messages) > 1 && $key < count($messages) - 1) {
             $lines[] = '';
         }
     }
     if ($padding && $this->isDecorated()) {
         array_unshift($lines, '');
         $lines[] = '';
     }
     foreach ($lines as &$line) {
         $line = sprintf('%s%s', $prefix, $line);
         $line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
         if ($style) {
             $line = sprintf('<%s>%s</>', $style, $line);
         }
     }
     $this->writeln($lines);
     $this->newLine();
 }
开发者ID:a53ali,项目名称:CakePhP,代码行数:40,代码来源:SymfonyStyle.php

示例2: getProgressBar

 protected function getProgressBar($nbIteration, $message)
 {
     $bar = new ProgressBar($this->output, $nbIteration);
     ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
         static $i = 0;
         $mem = memory_get_usage();
         $colors = $i++ ? '41;37' : '44;37';
         return "[" . $colors . 'm ' . Helper::formatMemory($mem) . " [0m";
     });
     $bar->setFormat(" [44;37m %title:-38s% [0m\n %current%/%max% %bar% %percent:3s%%\n :chequered_flag:  %remaining:-10s% %memory:37s%\n");
     $bar->setBarCharacter("[32m●[0m");
     $bar->setEmptyBarCharacter("[31m●[0m");
     $bar->setMessage($message, 'title');
     $bar->start();
     return $bar;
 }
开发者ID:petit2m,项目名称:seriesTracker,代码行数:16,代码来源:BaseCommand.php

示例3: render

 /**
  * Renders the title block to output.
  */
 public function render()
 {
     $this->output->writeln('');
     $lineLength = $this->getTerminalWidth();
     $lines = explode(PHP_EOL, wordwrap($this->message, $lineLength - (strlen($this->blockStyles[$this->style]['prefix']) + 3), PHP_EOL, true));
     array_unshift($lines, ' ');
     array_push($lines, ' ');
     foreach ($lines as $i => $line) {
         $prefix = str_repeat(' ', strlen($this->blockStyles[$this->style]['prefix']));
         if ($i === 1) {
             $prefix = $this->blockStyles[$this->style]['prefix'];
         }
         $line = sprintf(' %s %s', $prefix, $line);
         $this->output->writeln(sprintf('<%s>%s%s</>', $this->blockStyles[$this->style]['style'], $line, str_repeat(' ', $lineLength - Helper::strlenWithoutDecoration($this->output->getFormatter(), $line))));
     }
     $this->output->writeln('');
 }
开发者ID:accompli,项目名称:accompli,代码行数:20,代码来源:TitleBlock.php

示例4: getCellWidth

 /**
  * Gets cell width.
  *
  * @param array $row
  * @param int   $column
  *
  * @return int
  */
 private function getCellWidth(array $row, $column)
 {
     if (isset($row[$column])) {
         $cell = $row[$column];
         $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
         return $cellWidth;
     }
     return 0;
 }
开发者ID:levanigongadze,项目名称:Labweb,代码行数:17,代码来源:Table.php

示例5: askForPassword

 /**
  * Get password and validate.
  *
  * @param Helper   $helper
  * @param string   $question
  * @param callable $validator
  *
  * @return string
  */
 protected function askForPassword(Helper $helper, $question, callable $validator)
 {
     $question = new Question($question);
     $question->setValidator($validator);
     $question->setHidden(true);
     $question->setHiddenFallback(true);
     return $helper->ask($this->input, $this->output, $question);
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:17,代码来源:ChangePasswordCommand.php

示例6: formatStopwatchEvent

 /**
  * @param StopwatchEvent $event
  *
  * @return string
  */
 private function formatStopwatchEvent(StopwatchEvent $event)
 {
     return sprintf('Time: %s, Memory: %s.', Helper::formatTime($event->getDuration() / 1000), Helper::formatMemory($event->getMemory()));
 }
开发者ID:localheinz,项目名称:github-changelog,代码行数:9,代码来源:GenerateCommand.php

示例7: getCellWidth

 /**
  * Gets cell width.
  *
  * @param array $row
  * @param int   $column
  *
  * @return int
  */
 private function getCellWidth(array $row, $column)
 {
     if (isset($row[$column])) {
         $cell = $row[$column];
         $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
         if ($cell instanceof TableCell && $cell->getColspan() > 1) {
             // we assume that cell value will be across more than one column.
             $cellWidth = $cellWidth / $cell->getColspan();
         }
         return $cellWidth;
     }
     return 0;
 }
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:21,代码来源:Table.php

示例8: initPlaceholderFormatters

 private static function initPlaceholderFormatters()
 {
     return array('indicator' => function (ProgressIndicator $indicator) {
         return $indicator->indicatorValues[$indicator->indicatorCurrent % count($indicator->indicatorValues)];
     }, 'message' => function (ProgressIndicator $indicator) {
         return $indicator->message;
     }, 'elapsed' => function (ProgressIndicator $indicator) {
         return Helper::formatTime(time() - $indicator->startTime);
     }, 'memory' => function () {
         return Helper::formatMemory(memory_get_usage(true));
     });
 }
开发者ID:ayoah,项目名称:symfony,代码行数:12,代码来源:ProgressIndicator.php

示例9: displayAvancement

 protected function displayAvancement($options, $done, $size, $showProgress, $output, $progress)
 {
     //advance
     $done += $options['slice'];
     if ($done > $size) {
         $done = $size;
     }
     //showing where we're at.
     if ($showProgress) {
         if ($output->isDecorated()) {
             $progress->advance();
         } else {
             $output->writeln("did " . $done . " over (" . $size . ") memory: " . Helper::formatMemory(memory_get_usage(true)));
         }
     }
     return $done;
 }
开发者ID:conjecto,项目名称:nemrod,代码行数:17,代码来源:Populator.php

示例10: find

 /**
  * Finds a command by name or alias.
  *
  * Contrary to get, this command tries to find the best
  * match if you give it an abbreviation of a name or alias.
  *
  * @param string $name A command name or a command alias
  *
  * @return Command A Command instance
  *
  * @throws CommandNotFoundException When command name is incorrect or ambiguous
  */
 public function find($name)
 {
     $allCommands = array_keys($this->commands);
     $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
         return preg_quote($matches[1]) . '[^:]*';
     }, $name);
     $commands = preg_grep('{^' . $expr . '}', $allCommands);
     if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
         if (false !== ($pos = strrpos($name, ':'))) {
             // check if a namespace exists and contains commands
             $this->findNamespace(substr($name, 0, $pos));
         }
         $message = sprintf('Command "%s" is not defined.', $name);
         if ($alternatives = $this->findAlternatives($name, $allCommands)) {
             if (1 == count($alternatives)) {
                 $message .= "\n\nDid you mean this?\n    ";
             } else {
                 $message .= "\n\nDid you mean one of these?\n    ";
             }
             $message .= implode("\n    ", $alternatives);
         }
         throw new CommandNotFoundException($message, $alternatives);
     }
     // filter out aliases for commands which are already on the list
     if (count($commands) > 1) {
         $commandList = $this->commands;
         $commands = array_filter($commands, function ($nameOrAlias) use($commandList, $commands) {
             $commandName = $commandList[$nameOrAlias]->getName();
             return $commandName === $nameOrAlias || !in_array($commandName, $commands);
         });
     }
     $exact = in_array($name, $commands, true);
     if (count($commands) > 1 && !$exact) {
         $usableWidth = $this->terminal->getWidth() - 10;
         $abbrevs = array_values($commands);
         $maxLen = 0;
         foreach ($abbrevs as $abbrev) {
             $maxLen = max(Helper::strlen($abbrev), $maxLen);
         }
         $abbrevs = array_map(function ($cmd) use($commandList, $usableWidth, $maxLen) {
             $abbrev = str_pad($cmd, $maxLen, ' ') . ' ' . $commandList[$cmd]->getDescription();
             return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3) . '...' : $abbrev;
         }, array_values($commands));
         $suggestions = $this->getAbbreviationSuggestions($abbrevs);
         throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands));
     }
     return $this->get($exact ? $name : reset($commands));
 }
开发者ID:symfony,项目名称:symfony,代码行数:60,代码来源:Application.php

示例11: getRemaining

 /**
  * @return string
  */
 public function getRemaining()
 {
     if (!$this->getMaxSteps()) {
         return '???';
     }
     if (!$this->getProgress()) {
         $remaining = 0;
     } else {
         $remaining = round((time() - $this->getStartTime()) / $this->getProgress() * ($this->getMaxSteps() - $this->getProgress()));
     }
     return Helper::formatTime($remaining);
 }
开发者ID:ynloultratech,项目名称:framework,代码行数:15,代码来源:ProgressBar.php

示例12: render

 /**
  * Renders the title to output.
  */
 public function render()
 {
     $this->output->writeln(array('', sprintf('<title>%s</>', $this->message), sprintf('<title>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->output->getFormatter(), $this->message))), ''));
 }
开发者ID:deborahvandervegt,项目名称:accompli,代码行数:7,代码来源:Title.php

示例13: createBlock

 private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
 {
     $indentLength = 0;
     $prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
     $lines = array();
     if (null !== $type) {
         $type = sprintf('[%s] ', $type);
         $indentLength = strlen($type);
         $lineIndentation = str_repeat(' ', $indentLength);
     }
     // wrap and add newlines for each element
     foreach ($messages as $key => $message) {
         if ($escape) {
             $message = OutputFormatter::escape($message);
         }
         $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, PHP_EOL, true)));
         if (count($messages) > 1 && $key < count($messages) - 1) {
             $lines[] = '';
         }
     }
     foreach ($lines as $i => &$line) {
         if (null !== $type) {
             $line = 0 === $i ? $type . $line : $lineIndentation . $line;
         }
         $line = $prefix . $line;
         $line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
         if ($style) {
             $line = sprintf('<%s>%s</>', $style, $line);
         }
     }
     if ($padding && $this->isDecorated()) {
         array_unshift($lines, '');
         $lines[] = '';
     }
     return $lines;
 }
开发者ID:levanigongadze,项目名称:Labweb,代码行数:36,代码来源:SymfonyStyle.php

示例14: renderCell

 /**
  * Renders table cell with padding.
  *
  * @param array $row
  * @param int $column
  * @param string $cellFormat
  */
 private function renderCell(array $row, $column, $cellFormat)
 {
     $cell = isset($row[$column]) ? $row[$column] : '';
     $width = $this->columnWidths[$column];
     if ($cell instanceof TableCell && $cell->getColspan() > 1) {
         // add the width of the following columns(numbers of colspan).
         foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) {
             $width += $this->getColumnSeparatorWidth() + $this->columnWidths[$nextColumn];
         }
     }
     // str_pad won't work properly with multi-byte strings, we need to fix the padding
     if (false !== ($encoding = mb_detect_encoding($cell, null, true))) {
         $width += strlen($cell) - mb_strwidth($cell, $encoding);
     }
     $style = $this->getColumnStyle($column);
     if ($cell instanceof TableSeparator) {
         $this->output->write(sprintf($style->getBorderFormat(), str_repeat($style->getHorizontalBorderChar(), $width)));
     } else {
         $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
         $content = sprintf($style->getCellRowContentFormat(), $cell);
         $this->output->write(sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType())));
     }
 }
开发者ID:saj696,项目名称:pipe,代码行数:30,代码来源:Table.php

示例15: subSection

 /**
  * @param string $message
  */
 public function subSection($message)
 {
     $padLength = $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $message) - 6;
     $padLeft = round($padLength / 2);
     $padRight = $padLength - $padLeft;
     $this->autoPrependBlock();
     $this->writeln([sprintf('<bg=yellow;fg=black> %s[ %s ]%s </>', str_repeat(' ', $padLeft), $message, str_repeat(' ', $padRight))]);
     $this->newLine();
 }
开发者ID:src-run,项目名称:vermicious-console-io-library,代码行数:12,代码来源:Style.php


注:本文中的Symfony\Component\Console\Helper\Helper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。