Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
136
vendor/symfony/console/Helper/Table.php
vendored
136
vendor/symfony/console/Helper/Table.php
vendored
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Provides helpers to display a table.
|
||||
|
@ -19,6 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Саша Стаменковић <umpirsky@gmail.com>
|
||||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
||||
* @author Max Grigorian <maxakawizard@gmail.com>
|
||||
*/
|
||||
class Table
|
||||
{
|
||||
|
@ -60,6 +62,11 @@ class Table
|
|||
*/
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $columnStyles = array();
|
||||
|
||||
private static $styles;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
|
@ -102,7 +109,7 @@ class Table
|
|||
}
|
||||
|
||||
if (!self::$styles[$name]) {
|
||||
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return self::$styles[$name];
|
||||
|
@ -122,7 +129,7 @@ class Table
|
|||
} elseif (isset(self::$styles[$name])) {
|
||||
$this->style = self::$styles[$name];
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -138,6 +145,47 @@ class Table
|
|||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets table column style.
|
||||
*
|
||||
* @param int $columnIndex Column index
|
||||
* @param TableStyle|string $name The style name or a TableStyle instance
|
||||
*
|
||||
* @return Table
|
||||
*/
|
||||
public function setColumnStyle($columnIndex, $name)
|
||||
{
|
||||
$columnIndex = intval($columnIndex);
|
||||
|
||||
if ($name instanceof TableStyle) {
|
||||
$this->columnStyles[$columnIndex] = $name;
|
||||
} elseif (isset(self::$styles[$name])) {
|
||||
$this->columnStyles[$columnIndex] = self::$styles[$name];
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current style for a column.
|
||||
*
|
||||
* If style was not set, it returns the global table style.
|
||||
*
|
||||
* @param int $columnIndex Column index
|
||||
*
|
||||
* @return TableStyle
|
||||
*/
|
||||
public function getColumnStyle($columnIndex)
|
||||
{
|
||||
if (isset($this->columnStyles[$columnIndex])) {
|
||||
return $this->columnStyles[$columnIndex];
|
||||
}
|
||||
|
||||
return $this->getStyle();
|
||||
}
|
||||
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$headers = array_values($headers);
|
||||
|
@ -175,7 +223,7 @@ class Table
|
|||
}
|
||||
|
||||
if (!is_array($row)) {
|
||||
throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
|
||||
throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.');
|
||||
}
|
||||
|
||||
$this->rows[] = array_values($row);
|
||||
|
@ -205,24 +253,26 @@ class Table
|
|||
public function render()
|
||||
{
|
||||
$this->calculateNumberOfColumns();
|
||||
$this->rows = $this->buildTableRows($this->rows);
|
||||
$this->headers = $this->buildTableRows($this->headers);
|
||||
$rows = $this->buildTableRows($this->rows);
|
||||
$headers = $this->buildTableRows($this->headers);
|
||||
|
||||
$this->calculateColumnsWidth(array_merge($headers, $rows));
|
||||
|
||||
$this->renderRowSeparator();
|
||||
if (!empty($this->headers)) {
|
||||
foreach ($this->headers as $header) {
|
||||
if (!empty($headers)) {
|
||||
foreach ($headers as $header) {
|
||||
$this->renderRow($header, $this->style->getCellHeaderFormat());
|
||||
$this->renderRowSeparator();
|
||||
}
|
||||
}
|
||||
foreach ($this->rows as $row) {
|
||||
foreach ($rows as $row) {
|
||||
if ($row instanceof TableSeparator) {
|
||||
$this->renderRowSeparator();
|
||||
} else {
|
||||
$this->renderRow($row, $this->style->getCellRowFormat());
|
||||
}
|
||||
}
|
||||
if (!empty($this->rows)) {
|
||||
if (!empty($rows)) {
|
||||
$this->renderRowSeparator();
|
||||
}
|
||||
|
||||
|
@ -246,7 +296,7 @@ class Table
|
|||
|
||||
$markup = $this->style->getCrossingChar();
|
||||
for ($column = 0; $column < $count; ++$column) {
|
||||
$markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->getColumnWidth($column)).$this->style->getCrossingChar();
|
||||
$markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->columnWidths[$column]).$this->style->getCrossingChar();
|
||||
}
|
||||
|
||||
$this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
|
||||
|
@ -292,25 +342,27 @@ class Table
|
|||
private function renderCell(array $row, $column, $cellFormat)
|
||||
{
|
||||
$cell = isset($row[$column]) ? $row[$column] : '';
|
||||
$width = $this->getColumnWidth($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->getColumnWidth($nextColumn);
|
||||
$width += $this->getColumnSeparatorWidth() + $this->columnWidths[$nextColumn];
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
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($this->style->getBorderFormat(), str_repeat($this->style->getHorizontalBorderChar(), $width)));
|
||||
$this->output->write(sprintf($style->getBorderFormat(), str_repeat($style->getHorizontalBorderChar(), $width)));
|
||||
} else {
|
||||
$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())));
|
||||
$content = sprintf($style->getCellRowContentFormat(), $cell);
|
||||
$this->output->write(sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +384,7 @@ class Table
|
|||
$columns[] = $this->getNumberOfColumns($row);
|
||||
}
|
||||
|
||||
return $this->numberOfColumns = max($columns);
|
||||
$this->numberOfColumns = max($columns);
|
||||
}
|
||||
|
||||
private function buildTableRows($rows)
|
||||
|
@ -343,7 +395,6 @@ class Table
|
|||
|
||||
// Remove any new line breaks and replace it with a new line
|
||||
foreach ($rows[$rowKey] as $column => $cell) {
|
||||
$rows[$rowKey] = $this->fillCells($rows[$rowKey], $column);
|
||||
if (!strstr($cell, "\n")) {
|
||||
continue;
|
||||
}
|
||||
|
@ -363,7 +414,7 @@ class Table
|
|||
|
||||
$tableRows = array();
|
||||
foreach ($rows as $rowKey => $row) {
|
||||
$tableRows[] = $row;
|
||||
$tableRows[] = $this->fillCells($row);
|
||||
if (isset($unmergedRows[$rowKey])) {
|
||||
$tableRows = array_merge($tableRows, $unmergedRows[$rowKey]);
|
||||
}
|
||||
|
@ -429,21 +480,23 @@ class Table
|
|||
* fill cells for a row that contains colspan > 1.
|
||||
*
|
||||
* @param array $row
|
||||
* @param int $column
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function fillCells($row, $column)
|
||||
private function fillCells($row)
|
||||
{
|
||||
$cell = $row[$column];
|
||||
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
|
||||
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
|
||||
// insert empty value into rows at column position
|
||||
array_splice($row, $position, 0, '');
|
||||
$newRow = array();
|
||||
foreach ($row as $column => $cell) {
|
||||
$newRow[] = $cell;
|
||||
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
|
||||
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
|
||||
// insert empty value at column position
|
||||
$newRow[] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $row;
|
||||
return $newRow ?: $row;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -487,7 +540,7 @@ class Table
|
|||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return array()
|
||||
* @return array
|
||||
*/
|
||||
private function getRowColumns($row)
|
||||
{
|
||||
|
@ -503,34 +556,29 @@ class Table
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets column width.
|
||||
* Calculates columns widths.
|
||||
*
|
||||
* @param int $column
|
||||
*
|
||||
* @return int
|
||||
* @param array $rows
|
||||
*/
|
||||
private function getColumnWidth($column)
|
||||
private function calculateColumnsWidth($rows)
|
||||
{
|
||||
if (isset($this->columnWidths[$column])) {
|
||||
return $this->columnWidths[$column];
|
||||
}
|
||||
for ($column = 0; $column < $this->numberOfColumns; ++$column) {
|
||||
$lengths = array();
|
||||
foreach ($rows as $row) {
|
||||
if ($row instanceof TableSeparator) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (array_merge($this->headers, $this->rows) as $row) {
|
||||
if ($row instanceof TableSeparator) {
|
||||
continue;
|
||||
$lengths[] = $this->getCellWidth($row, $column);
|
||||
}
|
||||
|
||||
$lengths[] = $this->getCellWidth($row, $column);
|
||||
$this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2;
|
||||
}
|
||||
|
||||
return $this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets column width.
|
||||
*
|
||||
* @param int $column
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getColumnSeparatorWidth()
|
||||
|
|
Reference in a new issue