Table
in package
Provides helpers to display a table.
Tags
Table of Contents
Constants
- BORDER_INSIDE = 1
- BORDER_OUTSIDE = 0
- DISPLAY_ORIENTATION_DEFAULT = 'default'
- DISPLAY_ORIENTATION_HORIZONTAL = 'horizontal'
- DISPLAY_ORIENTATION_VERTICAL = 'vertical'
- SEPARATOR_BOTTOM = 3
- SEPARATOR_MID = 2
- SEPARATOR_TOP = 0
- SEPARATOR_TOP_BOTTOM = 1
Properties
- $columnMaxWidths : array<string|int, mixed>
- $columnStyles : array<string|int, mixed>
- $columnWidths : array<string|int, mixed>
- $displayOrientation : string
- $effectiveColumnWidths : array<string|int, mixed>
- $footerTitle : string|null
- $headers : array<string|int, mixed>
- $headerTitle : string|null
- $numberOfColumns : int
- $output : OutputInterface
- $rendered : bool
- $rows : array<string|int, mixed>
- $style : TableStyle
- $styles : array<string|int, mixed>
Methods
- __construct() : mixed
- addRow() : $this
- addRows() : $this
- appendRow() : $this
- 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() : void
- 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() : $this
- setHeaders() : $this
- setHeaderTitle() : $this
- setHorizontal() : $this
- setRow() : $this
- setRows() : $this
- setStyle() : $this
- Sets table style.
- setStyleDefinition() : void
- Sets a style definition.
- setVertical() : $this
- buildTableRows() : TableRows
- calculateColumnsWidth() : void
- Calculates columns widths.
- calculateNumberOfColumns() : void
- Calculate number of columns for this table.
- calculateRowCount() : int
- cleanup() : void
- Called after rendering to cleanup cache data.
- copyRow() : array<string|int, mixed>
- fillCells() : iterable<string|int, 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, TableStyle>
- renderCell() : string
- Renders table cell with padding.
- renderColumnSeparator() : string
- Renders vertical column separator.
- renderRow() : void
- Renders table row.
- renderRowSeparator() : void
- Renders horizontal header separator.
- resolveStyle() : TableStyle
Constants
BORDER_INSIDE
private
mixed
BORDER_INSIDE
= 1
BORDER_OUTSIDE
private
mixed
BORDER_OUTSIDE
= 0
DISPLAY_ORIENTATION_DEFAULT
private
mixed
DISPLAY_ORIENTATION_DEFAULT
= 'default'
DISPLAY_ORIENTATION_HORIZONTAL
private
mixed
DISPLAY_ORIENTATION_HORIZONTAL
= 'horizontal'
DISPLAY_ORIENTATION_VERTICAL
private
mixed
DISPLAY_ORIENTATION_VERTICAL
= 'vertical'
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
array<string|int, mixed>
$columnMaxWidths
= []
$columnStyles
private
array<string|int, mixed>
$columnStyles
= []
$columnWidths
private
array<string|int, mixed>
$columnWidths
= []
$displayOrientation
private
string
$displayOrientation
= self::DISPLAY_ORIENTATION_DEFAULT
$effectiveColumnWidths
private
array<string|int, mixed>
$effectiveColumnWidths
= []
$footerTitle
private
string|null
$footerTitle
= null
$headers
private
array<string|int, mixed>
$headers
= []
$headerTitle
private
string|null
$headerTitle
= null
$numberOfColumns
private
int
$numberOfColumns
$output
private
OutputInterface
$output
$rendered
private
bool
$rendered
= false
$rows
private
array<string|int, mixed>
$rows
= []
$style
private
TableStyle
$style
$styles
private
static array<string|int, mixed>
$styles
Methods
__construct()
public
__construct(OutputInterface $output) : mixed
Parameters
- $output : OutputInterface
addRow()
public
addRow(TableSeparator|array<string|int, mixed> $row) : $this
Parameters
- $row : TableSeparator|array<string|int, mixed>
Return values
$thisaddRows()
public
addRows(array<string|int, mixed> $rows) : $this
Parameters
- $rows : array<string|int, mixed>
Return values
$thisappendRow()
Adds a row to the table, and re-renders the table.
public
appendRow(TableSeparator|array<string|int, mixed> $row) : $this
Parameters
- $row : TableSeparator|array<string|int, mixed>
Return values
$thisgetColumnStyle()
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
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
Return values
TableStylerender()
Renders table to output.
public
render() : void
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
- $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
- $width : int
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) : $this
Parameters
- $title : string|null
Return values
$thissetHeaders()
public
setHeaders(array<string|int, mixed> $headers) : $this
Parameters
- $headers : array<string|int, mixed>
Return values
$thissetHeaderTitle()
public
setHeaderTitle(string|null $title) : $this
Parameters
- $title : string|null
Return values
$thissetHorizontal()
public
setHorizontal([bool $horizontal = true ]) : $this
Parameters
- $horizontal : bool = true
Return values
$thissetRow()
public
setRow(int|string $column, array<string|int, mixed> $row) : $this
Parameters
- $column : int|string
- $row : array<string|int, mixed>
Return values
$thissetRows()
public
setRows(array<string|int, mixed> $rows) : $this
Parameters
- $rows : array<string|int, mixed>
Return values
$thissetStyle()
Sets table style.
public
setStyle(TableStyle|string $name) : $this
Parameters
- $name : TableStyle|string
Return values
$thissetStyleDefinition()
Sets a style definition.
public
static setStyleDefinition(string $name, TableStyle $style) : void
Parameters
- $name : string
- $style : TableStyle
setVertical()
public
setVertical([bool $vertical = true ]) : $this
Parameters
- $vertical : bool = true
Return values
$thisbuildTableRows()
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) : void
Parameters
- $groups : iterable<string|int, mixed>
calculateNumberOfColumns()
Calculate number of columns for this table.
private
calculateNumberOfColumns(array<string|int, mixed> $rows) : void
Parameters
- $rows : array<string|int, mixed>
calculateRowCount()
private
calculateRowCount() : int
Return values
intcleanup()
Called after rendering to cleanup cache data.
private
cleanup() : void
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) : iterable<string|int, mixed>
Parameters
- $row : iterable<string|int, mixed>
Return values
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, TableStyle>
Return values
array<string, TableStyle>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|null $firstCellFormat = null ]) : void
Example:
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
Parameters
- $row : array<string|int, mixed>
- $cellFormat : string
- $firstCellFormat : string|null = null
renderRowSeparator()
Renders horizontal header separator.
private
renderRowSeparator([int $type = self::SEPARATOR_MID ][, string|null $title = null ][, string|null $titleFormat = null ]) : void
Example:
+-----+-----------+-------+
Parameters
- $type : int = self::SEPARATOR_MID
- $title : string|null = null
- $titleFormat : string|null = null
resolveStyle()
private
resolveStyle(TableStyle|string $name) : TableStyle
Parameters
- $name : TableStyle|string