2017 © Pedro Peláez
 

library console-table

Console Table

image

phplucidframe/console-table

Console Table

  • Sunday, July 15, 2018
  • by cithukyaw
  • Repository
  • 1 Watchers
  • 25 Stars
  • 6,422 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 12 Forks
  • 1 Open issues
  • 7 Versions
  • 37 % Grown

The README.md

PHP ConsoleTable

ConsoleTabe makes you easy to build console style tables. It helps you to display tabular data in terminal/shell. This is a component of PHPLucidFrame., (*1)

License: MIT, (*2)

Composer Installation

composer require phplucidframe/console-table

Example 1: Bordered Table (Default)

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->addHeader('Language')
    ->addHeader('Year')
    ->addRow()
        ->addColumn('PHP')
        ->addColumn(1994)
    ->addRow()
        ->addColumn('C++')
        ->addColumn(1983)
    ->addRow()
        ->addColumn('C')
        ->addColumn(1970)
    ->display()
;

You can also print the table using getTable method such as echo $table->getTable();, (*3)

Output:, (*4)

+----------+------+
| Language | Year |
+----------+------+
| PHP      | 1994 |
| C++      | 1983 |
| C        | 1970 |
+----------+------+

Example 2: Bordered Table with Padding Width 2

You can also use setHeaders() and addRow with Arrays., (*5)

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->setPadding(2)
    ->display()
;

Output:, (*6)

+------------+--------+
|  Language  |  Year  |
+------------+--------+
|  PHP       |  1994  |
|  C++       |  1983  |
|  C         |  1970  |
+------------+--------+

Example 3: Bordered Table with Left Margin Width 4

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->setIndent(4)
    ->display()
;

Output:, (*7)

    +----------+------+
    | Language | Year |
    +----------+------+
    | PHP      | 1994 |
    | C++      | 1983 |
    | C        | 1970 |
    +----------+------+

Example 4: Non-bordered Table with Header

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->hideBorder()
    ->display()
;

Output:, (*8)

 Language  Year
----------------
 PHP       1994
 C++       1983
 C         1970

Example 5: Non-bordered Table without Header

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->hideBorder()
    ->display()
;

Output:, (*9)

 PHP  1994
 C++  1983
 C    1970

Example 6: Table with all borders

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->showAllBorders()
    ->display()
;

Alternatively, you can use addBorderLine() for each row., (*10)

$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addBorderLine()
    ->addRow(array('C++', 1983))
    ->addBorderLine()
    ->addRow(array('C', 1970))
    ->display()
;

Output, (*11)

+----------+------+
| Language | Year |
+----------+------+
| PHP      | 1994 |
+----------+------+
| C++      | 1983 |
+----------+------+
| C        | 1970 |
+----------+------+

Test

If you have PHPUnit installed in your machine, you can run test at your project root., (*12)

composer install
phpunit tests

If you don't have PHPUnit, you can simply run this in your terminal., (*13)

php example.php

The Versions

15/07 2018

dev-master

9999999-dev

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

15/07 2018

v1.2.2

1.2.2.0

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

24/12 2017

v1.2.1

1.2.1.0

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

09/07 2017

v1.2.0

1.2.0.0

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

09/07 2017

dev-dev

dev-dev

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

26/09 2016

v1.1.0

1.1.0.0

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

22/09 2016

v1.0.0

1.0.0.0

Console Table

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires