Documentation

Table
in package

Provides helpers to display a table.

Tags
author

Fabien Potencier fabien@symfony.com

author

Саша Стаменковић umpirsky@gmail.com

author

Abdellatif Ait boudad a.aitboudad@gmail.com

author

Max Grigorian maxakawizard@gmail.com

author

Dany Maillard danymaillard93b@gmail.com

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

$rendered

private bool $rendered = false

$rows

private array<string|int, mixed> $rows = []

$styles

private static array<string|int, mixed> $styles

Methods

addRows()

public addRows(array<string|int, mixed> $rows) : $this
Parameters
$rows : array<string|int, mixed>
Return values
$this

appendRow()

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
$this

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

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() : 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
$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) : $this
Parameters
$title : string|null
Return values
$this

setHeaders()

public setHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>
Return values
$this

setHeaderTitle()

public setHeaderTitle(string|null $title) : $this
Parameters
$title : string|null
Return values
$this

setHorizontal()

public setHorizontal([bool $horizontal = true ]) : $this
Parameters
$horizontal : bool = true
Return values
$this

setRow()

public setRow(int|string $column, array<string|int, mixed> $row) : $this
Parameters
$column : int|string
$row : array<string|int, mixed>
Return values
$this

setRows()

public setRows(array<string|int, mixed> $rows) : $this
Parameters
$rows : array<string|int, mixed>
Return values
$this

setStyle()

Sets table style.

public setStyle(TableStyle|string $name) : $this
Parameters
$name : TableStyle|string
Return values
$this

setStyleDefinition()

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
$this

buildTableRows()

private buildTableRows(array<string|int, mixed> $rows) : TableRows
Parameters
$rows : array<string|int, mixed>
Return values
TableRows

calculateColumnsWidth()

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
int

cleanup()

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
throws
InvalidArgumentException
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>

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|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

        
On this page

Search results