Table
in package
Provides helpers to display a table.
Tags
Table of Contents
Constants
- BORDER_INSIDE = 1
- BORDER_OUTSIDE = 0
- SEPARATOR_BOTTOM = 3
- SEPARATOR_MID = 2
- SEPARATOR_TOP = 0
- SEPARATOR_TOP_BOTTOM = 1
Properties
- $columnMaxWidths : mixed
- $columnStyles : array<string|int, mixed>
- $columnWidths : array<string|int, mixed>
- User set column widths.
- $effectiveColumnWidths : mixed
- Column widths cache.
- $footerTitle : mixed
- $headers : mixed
- Table headers.
- $headerTitle : mixed
- $horizontal : mixed
- $numberOfColumns : int
- Number of columns cache.
- $output : OutputInterface
- $rendered : mixed
- $rows : mixed
- Table rows.
- $style : TableStyle
- $styles : mixed
Methods
- __construct() : mixed
- addRow() : mixed
- addRows() : mixed
- appendRow() : self
- Adds a row to the table, and re-renders the table.
- getColumnStyle() : TableStyle
- Gets the current style for a column.
- getStyle() : TableStyle
- Gets the current table style.
- getStyleDefinition() : TableStyle
- Gets a style definition by name.
- render() : mixed
- Renders table to output.
- setColumnMaxWidth() : $this
- Sets the maximum width of a column.
- setColumnStyle() : $this
- Sets table column style.
- setColumnWidth() : $this
- Sets the minimum width of a column.
- setColumnWidths() : $this
- Sets the minimum width of all columns.
- setFooterTitle() : self
- setHeaders() : mixed
- setHeaderTitle() : self
- setHorizontal() : self
- setRow() : mixed
- setRows() : mixed
- setStyle() : $this
- Sets table style.
- setStyleDefinition() : mixed
- Sets a style definition.
- buildTableRows() : TableRows
- calculateColumnsWidth() : mixed
- Calculates columns widths.
- calculateNumberOfColumns() : mixed
- Calculate number of columns for this table.
- calculateRowCount() : int
- cleanup() : mixed
- Called after rendering to cleanup cache data.
- copyRow() : array<string|int, mixed>
- fillCells() : mixed
- fill cells for a row that contains colspan > 1.
- fillNextRows() : array<string|int, mixed>
- fill rows that contains rowspan > 1.
- getCellWidth() : int
- getColumnSeparatorWidth() : int
- getNumberOfColumns() : int
- Gets number of columns by row.
- getRowColumns() : array<string|int, mixed>
- Gets list of columns for the given row.
- initStyles() : array<string|int, mixed>
- renderCell() : string
- Renders table cell with padding.
- renderColumnSeparator() : string
- Renders vertical column separator.
- renderRow() : mixed
- Renders table row.
- renderRowSeparator() : mixed
- Renders horizontal header separator.
- resolveStyle() : TableStyle
Constants
BORDER_INSIDE
private
mixed
BORDER_INSIDE
= 1
BORDER_OUTSIDE
private
mixed
BORDER_OUTSIDE
= 0
SEPARATOR_BOTTOM
private
mixed
SEPARATOR_BOTTOM
= 3
SEPARATOR_MID
private
mixed
SEPARATOR_MID
= 2
SEPARATOR_TOP
private
mixed
SEPARATOR_TOP
= 0
SEPARATOR_TOP_BOTTOM
private
mixed
SEPARATOR_TOP_BOTTOM
= 1
Properties
$columnMaxWidths
private
mixed
$columnMaxWidths
= []
$columnStyles
private
array<string|int, mixed>
$columnStyles
= []
$columnWidths
User set column widths.
private
array<string|int, mixed>
$columnWidths
= []
$effectiveColumnWidths
Column widths cache.
private
mixed
$effectiveColumnWidths
= []
$footerTitle
private
mixed
$footerTitle
$headers
Table headers.
private
mixed
$headers
= []
$headerTitle
private
mixed
$headerTitle
$horizontal
private
mixed
$horizontal
= false
$numberOfColumns
Number of columns cache.
private
int
$numberOfColumns
$output
private
OutputInterface
$output
$rendered
private
mixed
$rendered
= false
$rows
Table rows.
private
mixed
$rows
= []
$style
private
TableStyle
$style
$styles
private
static mixed
$styles
Methods
__construct()
public
__construct(OutputInterface $output) : mixed
Parameters
- $output : OutputInterface
addRow()
public
addRow(mixed $row) : mixed
Parameters
- $row : mixed
addRows()
public
addRows(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
appendRow()
Adds a row to the table, and re-renders the table.
public
appendRow(mixed $row) : self
Parameters
- $row : mixed
Return values
selfgetColumnStyle()
Gets the current style for a column.
public
getColumnStyle(int $columnIndex) : TableStyle
If style was not set, it returns the global table style.
Parameters
- $columnIndex : int
-
Column index
Return values
TableStylegetStyle()
Gets the current table style.
public
getStyle() : TableStyle
Return values
TableStylegetStyleDefinition()
Gets a style definition by name.
public
static getStyleDefinition(string $name) : TableStyle
Parameters
- $name : string
-
The style name
Return values
TableStylerender()
Renders table to output.
public
render() : mixed
Example:
+---------------+-----------------------+------------------+ | ISBN | Title | Author | +---------------+-----------------------+------------------+ | 99921-58-10-7 | Divine Comedy | Dante Alighieri | | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | +---------------+-----------------------+------------------+
setColumnMaxWidth()
Sets the maximum width of a column.
public
setColumnMaxWidth(int $columnIndex, int $width) : $this
Any cell within this column which contents exceeds the specified width will be wrapped into multiple lines, while formatted strings are preserved.
Parameters
- $columnIndex : int
- $width : int
Return values
$thissetColumnStyle()
Sets table column style.
public
setColumnStyle(int $columnIndex, TableStyle|string $name) : $this
Parameters
- $columnIndex : int
-
Column index
- $name : TableStyle|string
-
The style name or a TableStyle instance
Return values
$thissetColumnWidth()
Sets the minimum width of a column.
public
setColumnWidth(int $columnIndex, int $width) : $this
Parameters
- $columnIndex : int
-
Column index
- $width : int
-
Minimum column width in characters
Return values
$thissetColumnWidths()
Sets the minimum width of all columns.
public
setColumnWidths(array<string|int, mixed> $widths) : $this
Parameters
- $widths : array<string|int, mixed>
Return values
$thissetFooterTitle()
public
setFooterTitle(string|null $title) : self
Parameters
- $title : string|null
Return values
selfsetHeaders()
public
setHeaders(array<string|int, mixed> $headers) : mixed
Parameters
- $headers : array<string|int, mixed>
setHeaderTitle()
public
setHeaderTitle(string|null $title) : self
Parameters
- $title : string|null
Return values
selfsetHorizontal()
public
setHorizontal([bool $horizontal = true ]) : self
Parameters
- $horizontal : bool = true
Return values
selfsetRow()
public
setRow(mixed $column, array<string|int, mixed> $row) : mixed
Parameters
- $column : mixed
- $row : array<string|int, mixed>
setRows()
public
setRows(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
setStyle()
Sets table style.
public
setStyle(TableStyle|string $name) : $this
Parameters
- $name : TableStyle|string
-
The style name or a TableStyle instance
Return values
$thissetStyleDefinition()
Sets a style definition.
public
static setStyleDefinition(string $name, TableStyle $style) : mixed
Parameters
- $name : string
-
The style name
- $style : TableStyle
buildTableRows()
private
buildTableRows(array<string|int, mixed> $rows) : TableRows
Parameters
- $rows : array<string|int, mixed>
Return values
TableRowscalculateColumnsWidth()
Calculates columns widths.
private
calculateColumnsWidth(iterable<string|int, mixed> $groups) : mixed
Parameters
- $groups : iterable<string|int, mixed>
calculateNumberOfColumns()
Calculate number of columns for this table.
private
calculateNumberOfColumns(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
calculateRowCount()
private
calculateRowCount() : int
Return values
intcleanup()
Called after rendering to cleanup cache data.
private
cleanup() : mixed
copyRow()
private
copyRow(array<string|int, mixed> $rows, int $line) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
- $line : int
Return values
array<string|int, mixed>fillCells()
fill cells for a row that contains colspan > 1.
private
fillCells(iterable<string|int, mixed> $row) : mixed
Parameters
- $row : iterable<string|int, mixed>
fillNextRows()
fill rows that contains rowspan > 1.
private
fillNextRows(array<string|int, mixed> $rows, int $line) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
- $line : int
Tags
Return values
array<string|int, mixed>getCellWidth()
private
getCellWidth(array<string|int, mixed> $row, int $column) : int
Parameters
- $row : array<string|int, mixed>
- $column : int
Return values
intgetColumnSeparatorWidth()
private
getColumnSeparatorWidth() : int
Return values
intgetNumberOfColumns()
Gets number of columns by row.
private
getNumberOfColumns(array<string|int, mixed> $row) : int
Parameters
- $row : array<string|int, mixed>
Return values
intgetRowColumns()
Gets list of columns for the given row.
private
getRowColumns(array<string|int, mixed> $row) : array<string|int, mixed>
Parameters
- $row : array<string|int, mixed>
Return values
array<string|int, mixed>initStyles()
private
static initStyles() : array<string|int, mixed>
Return values
array<string|int, mixed>renderCell()
Renders table cell with padding.
private
renderCell(array<string|int, mixed> $row, int $column, string $cellFormat) : string
Parameters
- $row : array<string|int, mixed>
- $column : int
- $cellFormat : string
Return values
stringrenderColumnSeparator()
Renders vertical column separator.
private
renderColumnSeparator([int $type = self::BORDER_OUTSIDE ]) : string
Parameters
- $type : int = self::BORDER_OUTSIDE
Return values
stringrenderRow()
Renders table row.
private
renderRow(array<string|int, mixed> $row, string $cellFormat[, string $firstCellFormat = null ]) : mixed
Example:
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
Parameters
- $row : array<string|int, mixed>
- $cellFormat : string
- $firstCellFormat : string = null
renderRowSeparator()
Renders horizontal header separator.
private
renderRowSeparator([int $type = self::SEPARATOR_MID ][, string $title = null ][, string $titleFormat = null ]) : mixed
Example:
+-----+-----------+-------+
Parameters
- $type : int = self::SEPARATOR_MID
- $title : string = null
- $titleFormat : string = null
resolveStyle()
private
resolveStyle(mixed $name) : TableStyle
Parameters
- $name : mixed