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


PHP Helper::strlenWithoutDecoration方法代码示例

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


在下文中一共展示了Helper::strlenWithoutDecoration方法的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: 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

示例3: getCellWidth

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

示例4: overwrite

 /**
  * Overwrites a previous message to the output.
  *
  * @param string $message The message
  */
 private function overwrite($message)
 {
     // append whitespace to match the line's length
     if (null !== $this->lastMessagesLength) {
         if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $message)) {
             $message = str_pad($message, $this->lastMessagesLength, " ", STR_PAD_RIGHT);
         }
     }
     if ($this->output->isDecorated()) {
         $this->output->write("\r");
         $this->output->write($message);
     } else {
         $this->output->writeln($message);
     }
     $this->lastMessagesLength = 0;
     $len = Helper::strlenWithoutDecoration($this->output->getFormatter(), $message);
     if ($len > $this->lastMessagesLength) {
         $this->lastMessagesLength = $len;
     }
 }
开发者ID:ayoah,项目名称:symfony,代码行数:25,代码来源:ProgressIndicator.php

示例5: initPlaceholderFormatters

 private static function initPlaceholderFormatters()
 {
     return array('bar' => function (ProgressBar $bar, OutputInterface $output) {
         $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
         $display = str_repeat($bar->getBarCharacter(), $completeBars);
         if ($completeBars < $bar->getBarWidth()) {
             $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
             $display .= $bar->getProgressCharacter() . str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
         }
         return $display;
     }, 'elapsed' => function (ProgressBar $bar) {
         return Helper::formatTime(time() - $bar->getStartTime());
     }, 'remaining' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $remaining = 0;
         } else {
             $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
         }
         return Helper::formatTime($remaining);
     }, 'estimated' => function (ProgressBar $bar) {
         if (!$bar->getMaxSteps()) {
             throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
         }
         if (!$bar->getProgress()) {
             $estimated = 0;
         } else {
             $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
         }
         return Helper::formatTime($estimated);
     }, 'memory' => function (ProgressBar $bar) {
         return Helper::formatMemory(memory_get_usage(true));
     }, 'current' => function (ProgressBar $bar) {
         return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
     }, 'max' => function (ProgressBar $bar) {
         return $bar->getMaxSteps();
     }, 'percent' => function (ProgressBar $bar) {
         return floor($bar->getProgressPercent() * 100);
     });
 }
开发者ID:cilefen,项目名称:symfony,代码行数:42,代码来源:ProgressBar.php

示例6: subSection

 /**
  * {@inheritdoc}
  */
 public function subSection($message)
 {
     $this->writeln(array(sprintf('<comment>%s</comment>', $message), sprintf('<comment>%s</comment>', str_repeat('.', Helper::strlenWithoutDecoration($this->getFormatter(), $message)))));
     $this->newLine();
 }
开发者ID:hipay,项目名称:hipay-wallet-cashout-mirakl-integration,代码行数:8,代码来源:Style.php

示例7: buildLine

 /**
  * @return string
  */
 private function buildLine()
 {
     $regex = "{%([a-z\\-_]+)(?:\\:([^%]+))?%}i";
     $callback = function ($matches) {
         if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
             $text = call_user_func($formatter, $this, $this->output);
         } elseif (isset($this->messages[$matches[1]])) {
             $text = $this->messages[$matches[1]];
         } else {
             return $matches[0];
         }
         if (isset($matches[2])) {
             $text = sprintf('%' . $matches[2], $text);
         }
         return $text;
     };
     $line = preg_replace_callback($regex, $callback, $this->format);
     $lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
     $terminalWidth = $this->terminal->getWidth();
     if ($lineLength <= $terminalWidth) {
         return $line;
     }
     $this->setBarWidth($this->barWidth - $lineLength + $terminalWidth);
     return preg_replace_callback($regex, $callback, $this->format);
 }
开发者ID:unexge,项目名称:symfony,代码行数:28,代码来源:ProgressBar.php

示例8: overwrite

 /**
  * Overwrites a previous message to the output.
  *
  * @param string $message The message
  */
 private function overwrite($message)
 {
     $lines = explode("\n", $message);
     // append whitespace to match the line's length
     if (null !== $this->lastMessagesLength) {
         foreach ($lines as $i => $line) {
             if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $line)) {
                 $lines[$i] = str_pad($line, $this->lastMessagesLength, " ", STR_PAD_RIGHT);
             }
         }
     }
     if ($this->overwrite) {
         // move back to the beginning of the progress bar before redrawing it
         $this->output->write("\r");
     } elseif ($this->step > 0) {
         // move to new line
         $this->output->writeln('');
     }
     if ($this->formatLineCount) {
         $this->output->write(sprintf("[%dA", $this->formatLineCount));
     }
     $this->output->write(implode("\n", $lines));
     $this->lastMessagesLength = 0;
     foreach ($lines as $line) {
         $len = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
         if ($len > $this->lastMessagesLength) {
             $this->lastMessagesLength = $len;
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:35,代码来源:ProgressBar.php

示例9: 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

示例10: getCellWidth

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

示例11: 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);
     $indentLength = 0;
     $lines = array();
     if (null !== $type) {
         $typePrefix = sprintf('[%s] ', $type);
         $indentLength = strlen($typePrefix);
         $lineIndentation = str_repeat(' ', $indentLength);
     }
     // 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) - $indentLength, PHP_EOL, true)));
         // prefix each line with a number of spaces equivalent to the type length
         if (null !== $type) {
             foreach ($lines as &$line) {
                 $line = $lineIndentation === substr($line, 0, $indentLength) ? $line : $lineIndentation . $line;
             }
         }
         if (count($messages) > 1 && $key < count($messages) - 1) {
             $lines[] = '';
         }
     }
     if (null !== $type) {
         $lines[0] = substr_replace($lines[0], $typePrefix, 0, $indentLength);
     }
     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:christengc,项目名称:wheel,代码行数:51,代码来源:SymfonyStyle.php

示例12: 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->getColumnWidth($column);
     // str_pad won't work properly with multi-byte strings, we need to fix the padding
     if (function_exists('mb_strwidth') && false !== ($encoding = mb_detect_encoding($cell))) {
         $width += strlen($cell) - mb_strwidth($cell, $encoding);
     }
     $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
     $content = sprintf($this->style->getCellRowContentFormat(), $cell);
     $this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:19,代码来源:Table.php

示例13: 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

示例14: 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

示例15: 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


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