PHP Class Platformsh\Cli\Util\Table

Usage: In a command's configure() method, add the --format option: Table::addFormatOption($this->getDefinition()); In a command's execute() method, build and display the table: $table = new Table($input, $output); $header = ['Column 1', 'Column 2', 'Column 3']; $rows = [ ['Cell 1', 'Cell 2', 'Cell 3'], ['Cell 4', 'Cell 5', 'Cell 6'], ]; $table->render($rows, $header);
Show file Open project: commerceguys/platform-cli Class Usage Examples

Protected Properties

Property Type Description
$input
$output

Public Methods

Method Description
__construct ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
addFormatOption ( Symfony\Component\Console\Input\InputDefinition $definition ) Add the --format option to a command's input definition.
formatIsMachineReadable ( ) : boolean Find whether the user wants machine-readable output.
render ( array $rows, array $header = [] ) Render a table of data to output.
renderSimple ( array $values, array $propertyNames ) Render an single-dimensional array of values, with their property names.

Protected Methods

Method Description
getFormat ( ) : string | null Get the user-specified format.
renderCsv ( array $rows, array $header, string $delimiter = ',', string $enclosure = '"' ) Render CSV output.
renderTable ( array $rows, array $header ) Render a Symfony Console table.

Method Details

__construct() public method

public __construct ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface

addFormatOption() public static method

Add the --format option to a command's input definition.
public static addFormatOption ( Symfony\Component\Console\Input\InputDefinition $definition )
$definition Symfony\Component\Console\Input\InputDefinition

formatIsMachineReadable() public method

Find whether the user wants machine-readable output.
public formatIsMachineReadable ( ) : boolean
return boolean True if the user has specified a machine-readable format via the --format option (e.g. 'csv' or 'tsv'), false otherwise.

getFormat() protected method

Get the user-specified format.
protected getFormat ( ) : string | null
return string | null

render() public method

Render a table of data to output.
public render ( array $rows, array $header = [] )
$rows array The table rows.
$header array The table header (optional).

renderCsv() protected method

Render CSV output.
protected renderCsv ( array $rows, array $header, string $delimiter = ',', string $enclosure = '"' )
$rows array
$header array
$delimiter string
$enclosure string

renderSimple() public method

Render an single-dimensional array of values, with their property names.
public renderSimple ( array $values, array $propertyNames )
$values array
$propertyNames array

renderTable() protected method

Render a Symfony Console table.
protected renderTable ( array $rows, array $header )
$rows array
$header array

Property Details

$input protected property

protected $input

$output protected property

protected $output