Creating tables to be printed to the console.
Every ezcConsoleTable object can be accessed as if it was a multidimensional, numerically indexed array. The first dimension represents the rows of the table, so $table[0] gives you access to the first row of the table, which is represented by a ezcConsoleTableRow object. You can access its properties directly, using e.g. $table[0]->format. The second dimension gives you direct access to the cells of your table, like $table[0][0] accesses the first cell in the first row of your table. You can access its properties diretly here, too. This works like e.g. $table[0][0]->format. Table row and cell objects are created on the fly, when you access them for the first time. You can also create them as if you simply create new array elements. E.g. $table[] creates a new row in the table.
Source for this file: /ConsoleTools/src/table.php
Version: | //autogen// |
ALIGN_CENTER
= STR_PAD_BOTH
|
Align text in cells to the center. |
ALIGN_DEFAULT
= -1
|
Align text in the default direction. |
ALIGN_LEFT
= STR_PAD_RIGHT
|
Align text in cells to the right. |
ALIGN_RIGHT
= STR_PAD_LEFT
|
Align text in cells to the left. |
WIDTH_FIXED
= 1
|
The width given by settings must be used even if the data allows it smaller. |
WIDTH_MAX
= 2
|
The width given by settings is a maximum value, if data allows it, the table gets smaller. |
WRAP_AUTO
= 1
|
Automatically wrap text to fit into a column. |
WRAP_CUT
= 3
|
Text will be cut to fit into a column. |
WRAP_NONE
= 2
|
Do not wrap text. Columns will be extended to fit the largest text. ATTENTION: This is risky! |
ezcConsoleTableOptions | read/write |
$options
Contains the options for this class. |
int | read/write |
$width
Width of the table. |
protected ezcConsoleOutput |
$outputHandler
The ezcConsoleOutput object to use. |
protected array(string=>mixed) |
$properties
Container to hold the properties |
protected array(ezcConsoleTableRow) |
$rows
Collection of the rows that are contained in the table. |
public ezcConsoleTable |
__construct(
$outHandler
, $width
, [ $options
= array()] )
Creates a new table. |
public int |
count(
)
Returns the number of cells in the row. |
public ezcConsoleTableCell |
current(
)
Returns the currently selected cell. |
public ezcConsoleTableOptions |
getOptions(
)
Returns the current options. |
public array |
getTable(
)
Returns the table in an array. |
public int |
key(
)
Returns the key of the currently selected cell. |
public mixed |
next(
)
Returns the next cell and selects it or false on the last cell. |
public bool |
offsetExists(
$offset
)
Returns if the given offset exists. |
public ezcConsoleTableCell |
offsetGet(
$offset
)
Returns the element with the given offset. |
public void |
offsetSet(
$offset
, $value
)
Set the element with the given offset. |
public void |
offsetUnset(
$offset
)
Unset the element with the given offset. |
public void |
outputTable(
)
Output the table. |
public ezcConsoleTableCell |
rewind(
)
Selects the very first cell and returns it. |
public void |
setOptions(
[ $options
= array()] )
Set new options. |
public ezcConsoleTableCell |
valid(
)
Returns if the current cell is valid. |
public string |
__toString(
)
Returns the table in a string. |
Creates a new table.
Name | Type | Description |
---|---|---|
$outHandler |
ezcConsoleOutput | Output handler to utilize |
$width |
int | Overall width of the table (chars). |
$options |
array | Options |
Type | Description |
---|---|
ezcBaseValueException |
On an invalid setting. |
Returns the number of cells in the row.
This method is part of the Countable interface to allow the usage of PHP's count() function to check how many cells this row has.
Method | Description |
---|---|
Countable::count |
Returns the currently selected cell.
This method is part of the Iterator interface to allow access to the cells of this row by iterating over it like an array (e.g. using foreach).
Method | Description |
---|---|
Iterator::current |
Returns the current options.
Returns the options currently set for this table.
Returns the table in an array.
Returns the entire table as an array of printable lines. Each element of the array represents a physical line of the drawn table, including all borders and stuff, so you can simply print the table using
Returns the key of the currently selected cell.
This method is part of the Iterator interface to allow access to the cells of this row by iterating over it like an array (e.g. using foreach).
Method | Description |
---|---|
Iterator::key |
Returns the next cell and selects it or false on the last cell.
This method is part of the Iterator interface to allow access to the cells of this row by iterating over it like an array (e.g. using foreach).
Method | Description |
---|---|
Iterator::next |
Returns if the given offset exists.
This method is part of the ArrayAccess interface to allow access to the data of this object as if it was an array.
Name | Type | Description |
---|---|---|
$offset |
int | The offset to check. |
Type | Description |
---|---|
ezcBaseValueException |
If a non numeric row ID is requested. |
Method | Description |
---|---|
ArrayAccess::offsetExists |
Returns the element with the given offset.
This method is part of the ArrayAccess interface to allow access to the data of this object as if it was an array. In case of the ezcConsoleTable class this method always returns a valid row object since it creates them on the fly, if a given item does not exist.
Name | Type | Description |
---|---|---|
$offset |
int | The offset to check. |
Type | Description |
---|---|
ezcBaseValueException |
If a non numeric row ID is requested. |
Method | Description |
---|---|
ArrayAccess::offsetGet |
Set the element with the given offset.
This method is part of the ArrayAccess interface to allow access to the data of this object as if it was an array.
Name | Type | Description |
---|---|---|
$offset |
int | The offset to assign an item to. |
$value |
ezcConsoleTableRow | The row to assign. |
Type | Description |
---|---|
ezcBaseValueException |
If the provided value is not of type ezcConsoleTableRow. |
ezcBaseValueException |
If a non numeric row ID is requested. |
Method | Description |
---|---|
ArrayAccess::offsetSet |
Unset the element with the given offset.
This method is part of the ArrayAccess interface to allow access to the data of this object as if it was an array.
Name | Type | Description |
---|---|---|
$offset |
int | The offset to unset the value for. |
Type | Description |
---|---|
ezcBaseValueException |
If a non numeric row ID is requested. |
Method | Description |
---|---|
ArrayAccess::offsetUnset |
Output the table.
Prints the complete table to the console.
Selects the very first cell and returns it.
This method is part of the Iterator interface to allow access to the cells of this row by iterating over it like an array (e.g. using foreach).
Method | Description |
---|---|
Iterator::rewind |
Set new options.
This method allows you to change the options of the table.
Name | Type | Description |
---|---|---|
$options |
ezcConsoleTableOptions | The options to set. |
Type | Description |
---|---|
ezcBaseSettingNotFoundException |
If you tried to set a non-existent option value. |
ezcBaseSettingValueException |
If the value is not valid for the desired option. |
ezcBaseValueException |
If you submit neither an array nor an instance of ezcConsoleTableOptions. |
Returns if the current cell is valid.
This method is part of the Iterator interface to allow access to the cells of this row by iterating over it like an array (e.g. using foreach).
Method | Description |
---|---|
Iterator::valid |
Returns the table in a string.