ConsoleTools: ezcConsoleTable
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcConsoleTable
|
Creating tables to be printed to the console. [
source]
Implemented Interfaces
- Countable (internal interface)
- Iterator (internal interface)
- ArrayAccess (internal interface)
1. // Initialize the console output handler
2. $out = new ezcConsoleOutput();
3. // Define a new format "headline"
4. $out->formats->headline->color = 'red';
5. $out->formats->headline->style = array( 'bold' );
6. // Define a new format "sum"
7. $out->formats->sum->color = 'blue';
8. $out->formats->sum->style = array( 'negative' );
9.
10. // Create a new table
11. $table = new ezcConsoleTable( $out, 60 );
12.
13. // Create first row and in it the first cell
14. $table[0][0]->content = 'Headline 1';
15.
16. // Create 3 more cells in row 0
17. for ( $i = 2; $i < 5; $i++ )
18. {
19. $table[0][]->content = "Headline $i";
20. }
21.
22. $data = array( 1, 2, 3, 4 );
23.
24. // Create some more data in the table...
25. foreach ( $data as $value )
26. {
27. // Create a new row each time and set it's contents to the actual value
28. $table[][0]->content = $value;
29. }
30.
31. // Set another border format for our headline row
32. $table[0]->borderFormat = 'headline';
33.
34. // Set the content format for all cells of the 3rd row to "sum"
35. $table[2]->format = 'sum';
36.
37. $table->outputTable();
Constants
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. |
Member Variables
Method Summary
|
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 array |
getTable(
)
Returns the table in a string. |
|
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 )
|
|
public ezcConsoleTableCell |
valid(
)
Returns if the current cell is valid. |
|
public mixed |
__get(
$key )
Property read access. |
|
public bool |
__isset(
$key )
Property isset access. |
|
public void |
__set(
$key, $val )
Property write access. |
Methods
__construct
ezcConsoleTable __construct(
ezcConsoleOutput
$outHandler, int
$width, [
$options = array()] )
Creates a new table.
Parameters
Throws
| Class | Description |
ezcBaseValueException |
On an invalid setting. |
See also:
ezcConsoleTable::$options,
ezcConsoleTable::$settings.
count
int count(
)
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.
current
Returns the currently selected cell.
This method is part of the Iterator interface to allow acces to the cells of this row by iterating over it like an array (e.g. using foreach).
getTable
array getTable(
)
Returns the table in a string.
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
1. echo implode( "\n" , $table->getTable() ):
which is basically what
ezcConsoleTable::outputTable() does.
key
int key(
)
Returns the key of the currently selected cell.
This method is part of the Iterator interface to allow acces to the cells of this row by iterating over it like an array (e.g. using foreach).
next
mixed next(
)
Returns the next cell and selects it or false on the last cell.
This method is part of the Iterator interface to allow acces to the cells of this row by iterating over it like an array (e.g. using foreach).
offsetExists
bool offsetExists(
int
$offset )
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.
Parameters
| Name |
Type |
Description |
$offset |
int |
The offset to check. |
Throws
| Class | Description |
ezcBaseValueException |
If a non numeric row ID is requested. |
offsetGet
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.
Parameters
| Name |
Type |
Description |
$offset |
int |
The offset to check. |
Throws
| Class | Description |
ezcBaseValueException |
If a non numeric row ID is requested. |
offsetSet
void offsetSet(
int
$offset, mixed
$value )
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.
Parameters
| Name |
Type |
Description |
$offset |
int |
The offset to assign an item to. |
Throws
| Class | Description |
ezcBaseValueException |
If a non numeric row ID is requested. |
ezcBaseValueException |
If the provided value is not of type {@ling ezcConsoleTableRow}. |
offsetUnset
void offsetUnset(
int
$offset )
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.
Parameters
| Name |
Type |
Description |
$offset |
int |
The offset to unset the value for. |
Throws
| Class | Description |
ezcBaseValueException |
If a non numeric row ID is requested. |
outputTable
void outputTable(
)
Output the table.
Prints the complete table to the console.
rewind
Selects the very first cell and returns it.
This method is part of the Iterator interface to allow acces to the cells of this row by iterating over it like an array (e.g. using foreach).
setOptions
void setOptions(
$options )
Parameters
| Name |
Type |
Description |
$options |
array |
|
valid
Returns if the current cell is valid.
This method is part of the Iterator interface to allow acces to the cells of this row by iterating over it like an array (e.g. using foreach).
__get
mixed __get(
string
$key )
Property read access.
Parameters
| Name |
Type |
Description |
$key |
string |
Name of the property. |
Throws
| Class | Description |
ezcBasePropertyNotFoundException |
If the the desired property is not found. |
__isset
bool __isset(
string
$key )
Property isset access.
Parameters
| Name |
Type |
Description |
$key |
string |
Name of the property. |
__set
void __set(
string
$key, mixed
$val )
Property write access.
Parameters
| Name |
Type |
Description |
$key |
string |
Name of the property. |
$val |
mixed |
The value for the property. |
Throws
| Class | Description |
ezcBasePropertyNotFoundException |
If a the value for the property options is not an instance of |
ezcBaseValueException |
If a the value for a property is out of range. |
Last updated: Fri, 02 Nov 2007