Text UI
A simple and fast way to take user input and display output in text mode using PHP.
Loading...
Searching...
No Matches
Table Class Reference
Inheritance diagram for Table:
DrawableInterface

Public Member Functions

 __construct (array $data)
 
 draw ()
 
 setHeader (array $header)
 
 setFooter (array $footer)
 
 setColWidths (array $widths)
 
 setHorizontalAlignements (array $alignements)
 
 setIntersectionChar (string $char)
 
 setSimpleHorizontalBorderChar (string $char)
 
 setSimpleVerticalBorderChar (string $char)
 
 setSpecialHorizontalBorderChar (string $char)
 
- Public Member Functions inherited from DrawableInterface

Protected Member Functions

 buildFooterStr (array $footer, array $colsLen, array $align)
 
 buildHeaderStr (array $header, array $colsLen, array $align)
 
 buildBodyStr (array $bodyData, array $colsLen, array $align)
 
 getAlign (int $colIndex, array $align)
 
 calcMaxParagraphByRow (array $row)
 
 splitCells (array $data, array $colsLen)
 
 buildBodyHorizontalSeparatorStr (array $colsLen)
 
 buildHeaderHorizontalSeparatorStr (array $colsLen)
 
 calcColsLen (array $data, array $width=[])
 
 calcColsLenFromData (array $data)
 
 calcColsLenFromWidth (array $width)
 

Protected Attributes

string $intersectionChar = '+'
 
string $simpleHorizontalBorderChar = '-'
 
string $verticalBorderChar = '|'
 
string $specialHorizontalBorderChar = '='
 
readonly array $data
 
array $header = []
 
array $footer = []
 
array $width = []
 
array $align = []
 

Detailed Description

Draws a table for displaying tabular data, with support for header, footer, alignment, and column sizes.

Author
everton3x @SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.ExcessiveClassComplexity)

Definition at line 18 of file Table.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array $data)
Parameters
array<mixed>$data The data to display is in the form of a multidimensional array rows->columns. Rows must have numeric keys, and columns can have numeric or text keys.

Definition at line 56 of file Table.php.

Member Function Documentation

◆ buildBodyHorizontalSeparatorStr()

buildBodyHorizontalSeparatorStr ( array $colsLen)
protected
Parameters
array<int>$colsLen
Returns
string

Definition at line 327 of file Table.php.

◆ buildBodyStr()

buildBodyStr ( array $bodyData,
array $colsLen,
array $align )
protected
Parameters
array<mixed>$bodyData
array<int>$colsLen
array<int>$align
Returns
string

Definition at line 221 of file Table.php.

◆ buildFooterStr()

buildFooterStr ( array $footer,
array $colsLen,
array $align )
protected
Parameters
array<string>$footer
array<int>$colsLen
array<int>$align
Returns
string

Definition at line 158 of file Table.php.

◆ buildHeaderHorizontalSeparatorStr()

buildHeaderHorizontalSeparatorStr ( array $colsLen)
protected
Parameters
array<int>$colsLen
Returns
string

Definition at line 342 of file Table.php.

◆ buildHeaderStr()

buildHeaderStr ( array $header,
array $colsLen,
array $align )
protected
Parameters
array<string>$header
array<int>$colsLen
array<int>$align
Returns
string

Definition at line 186 of file Table.php.

◆ calcColsLen()

calcColsLen ( array $data,
array $width = [] )
protected
Parameters
array<mixed>$data
array<int>$width
Returns
array<int>

Definition at line 358 of file Table.php.

◆ calcColsLenFromData()

calcColsLenFromData ( array $data)
protected
Parameters
array<mixed>$data
Returns
array<int> @SuppressWarnings(PHPMD.StaticAccess)

Definition at line 372 of file Table.php.

◆ calcColsLenFromWidth()

calcColsLenFromWidth ( array $width)
protected
Parameters
array<int>$width
Returns
array<int> @SuppressWarnings(PHPMD.StaticAccess)

Definition at line 386 of file Table.php.

◆ calcMaxParagraphByRow()

calcMaxParagraphByRow ( array $row)
protected
Parameters
array<int,array<string>>$row
Returns
int

Definition at line 285 of file Table.php.

◆ draw()

draw ( )

Draw the table.

Returns
void

Implements DrawableInterface.

Definition at line 66 of file Table.php.

◆ getAlign()

getAlign ( int $colIndex,
array $align )
protected
Parameters
int$colIndex
array<int>$align
Returns
int
Exceptions
InvalidArgumentException

Definition at line 263 of file Table.php.

◆ setColWidths()

setColWidths ( array $widths)

Sets the column widths.

Values ​​can be expressed in whole numbers representing parts of the whole or in decimals representing percentages.

Parameters
array<int>$widths The widths of each column, as many as there are columns of data.
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 124 of file Table.php.

◆ setFooter()

setFooter ( array $footer)

Sets the table footer.

Parameters
array<string>$footer A simple array with the footer labels or values. It should have the same number of columns as the data.
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 104 of file Table.php.

◆ setHeader()

setHeader ( array $header)

Sets the table header.

Parameters
array<string>$header A simple array with the header labels. It should have the same number of columns as the data.
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 87 of file Table.php.

◆ setHorizontalAlignements()

setHorizontalAlignements ( array $alignements)

Sets the horizontal alignment (center, right, or left - the default) of cell contents, including the header and footer.

It is not necessary to indicate alignment for all columns. Columns are identified by the 0-indexed key according to the order in which they appear in the data.

Parameters
array<int>$alignements Array of TextUI\Enum\HAlign
Returns
Table

Definition at line 145 of file Table.php.

◆ setIntersectionChar()

setIntersectionChar ( string $char)

Sets the single character that is used at the intersection between edges.

Parameters
string$char
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 412 of file Table.php.

◆ setSimpleHorizontalBorderChar()

setSimpleHorizontalBorderChar ( string $char)

Sets the single character that is used for horizontal borders between data.

Parameters
string$char
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 429 of file Table.php.

◆ setSimpleVerticalBorderChar()

setSimpleVerticalBorderChar ( string $char)

Sets the single character that is used for vertical borders.

Parameters
string$char
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 445 of file Table.php.

◆ setSpecialHorizontalBorderChar()

setSpecialHorizontalBorderChar ( string $char)

Sets the single character that is used for the horizontal borders of the header and footer and table boundaries.

Parameters
string$char
Returns
Table
Exceptions
InvalidArgumentException

Definition at line 462 of file Table.php.

◆ splitCells()

splitCells ( array $data,
array $colsLen )
protected
Parameters
array<int,array<string>>$data
array<int>$colsLen
Returns
array<mixed> @SuppressWarnings(PHPMD.StaticAccess)

Definition at line 304 of file Table.php.

Field Documentation

◆ $align

array $align = []
protected

Definition at line 48 of file Table.php.

◆ $data

readonly array $data
protected

Definition at line 28 of file Table.php.

◆ $footer

array $footer = []
protected

Definition at line 38 of file Table.php.

◆ $header

array $header = []
protected

Definition at line 33 of file Table.php.

◆ $intersectionChar

string $intersectionChar = '+'
protected

Definition at line 20 of file Table.php.

◆ $simpleHorizontalBorderChar

string $simpleHorizontalBorderChar = '-'
protected

Definition at line 21 of file Table.php.

◆ $specialHorizontalBorderChar

string $specialHorizontalBorderChar = '='
protected

Definition at line 23 of file Table.php.

◆ $verticalBorderChar

string $verticalBorderChar = '|'
protected

Definition at line 22 of file Table.php.

◆ $width

array $width = []
protected

Definition at line 43 of file Table.php.


The documentation for this class was generated from the following file: