Table
in package
Provides helpers to display a table.
Tags
Table of Contents
- BORDER_INSIDE = 1
- BORDER_OUTSIDE = 0
- SEPARATOR_BOTTOM = 3
- SEPARATOR_MID = 2
- SEPARATOR_TOP = 0
- SEPARATOR_TOP_BOTTOM = 1
- $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
- __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
= ""
SEPARATOR_BOTTOM
private
mixed
SEPARATOR_BOTTOM
= 3
SEPARATOR_MID
private
mixed
SEPARATOR_MID
= 2
SEPARATOR_TOP
private
mixed
SEPARATOR_TOP
= ""
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
Return values
mixed —addRow()
public
addRow(mixed $row) : mixed
Parameters
- $row : mixed
Return values
mixed —addRows()
public
addRows(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
Return values
mixed —appendRow()
Adds a row to the table, and re-renders the table.
public
appendRow(mixed $row) : self
Parameters
- $row : mixed
Return values
self —getColumnStyle()
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
Return values
TableStyle —getStyle()
Gets the current table style.
public
getStyle() : TableStyle
Return values
TableStyle —getStyleDefinition()
Gets a style definition by name.
public
static getStyleDefinition(string $name) : TableStyle
Parameters
- $name : string
Return values
TableStyle —render()
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 | +---------------+-----------------------+------------------+
Return values
mixed —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
$this —setColumnStyle()
Sets table column style.
public
setColumnStyle(int $columnIndex, TableStyle|string $name) : $this
Parameters
- $columnIndex : int
- $name : TableStyle|string
-
The style name or a TableStyle instance
Return values
$this —setColumnWidth()
Sets the minimum width of a column.
public
setColumnWidth(int $columnIndex, int $width) : $this
Parameters
- $columnIndex : int
- $width : int
Return values
$this —setColumnWidths()
Sets the minimum width of all columns.
public
setColumnWidths(array<string|int, mixed> $widths) : $this
Parameters
- $widths : array<string|int, mixed>
Return values
$this —setFooterTitle()
public
setFooterTitle(string|null $title) : self
Parameters
- $title : string|null
Return values
self —setHeaders()
public
setHeaders(array<string|int, mixed> $headers) : mixed
Parameters
- $headers : array<string|int, mixed>
Return values
mixed —setHeaderTitle()
public
setHeaderTitle(string|null $title) : self
Parameters
- $title : string|null
Return values
self —setHorizontal()
public
setHorizontal([bool $horizontal = true ]) : self
Parameters
- $horizontal : bool = true
Return values
self —setRow()
public
setRow(mixed $column, array<string|int, mixed> $row) : mixed
Parameters
- $column : mixed
- $row : array<string|int, mixed>
Return values
mixed —setRows()
public
setRows(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
Return values
mixed —setStyle()
Sets table style.
public
setStyle(TableStyle|string $name) : $this
Parameters
- $name : TableStyle|string
-
The style name or a TableStyle instance
Return values
$this —setStyleDefinition()
Sets a style definition.
public
static setStyleDefinition(string $name, TableStyle $style) : mixed
Parameters
- $name : string
- $style : TableStyle
Return values
mixed —buildTableRows()
private
buildTableRows(array<string|int, mixed> $rows) : TableRows
Parameters
- $rows : array<string|int, mixed>
Return values
TableRows —calculateColumnsWidth()
Calculates columns widths.
private
calculateColumnsWidth(iteratable<string|int, mixed> $rows) : mixed
Parameters
- $rows : iteratable<string|int, mixed>
Return values
mixed —calculateNumberOfColumns()
Calculate number of columns for this table.
private
calculateNumberOfColumns(array<string|int, mixed> $rows) : mixed
Parameters
- $rows : array<string|int, mixed>
Return values
mixed —calculateRowCount()
private
calculateRowCount() : int
Return values
int —cleanup()
Called after rendering to cleanup cache data.
private
cleanup() : mixed
Return values
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(mixed $row) : mixed
Parameters
- $row : mixed
Return values
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
int —getColumnSeparatorWidth()
private
getColumnSeparatorWidth() : int
Return values
int —getNumberOfColumns()
Gets number of columns by row.
private
getNumberOfColumns(array<string|int, mixed> $row) : int
Parameters
- $row : array<string|int, mixed>
Return values
int —getRowColumns()
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
string —renderColumnSeparator()
Renders vertical column separator.
private
renderColumnSeparator([int $type = self::BORDER_OUTSIDE ]) : string
Parameters
- $type : int = self::BORDER_OUTSIDE
Return values
string —renderRow()
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
Return values
mixed —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
Return values
mixed —resolveStyle()
private
resolveStyle(mixed $name) : TableStyle
Parameters
- $name : mixed