N98\Util\Console\Helper\Table\Renderer\TextRenderer::render PHP Method

render() public method

public render ( Symfony\Component\Console\Output\OutputInterface $output, array $rows ) : void
$output Symfony\Component\Console\Output\OutputInterface
$rows array headers are expected to be the keys of the first row.
return void
    public function render(OutputInterface $output, array $rows)
    {
        $table = new Table($output);
        $table->setStyle(new TableStyle());
        $table->setHeaders(array_keys($rows[0]));
        $table->setRows($rows);
        $table->render();
    }

Usage Example

    /**
     * @test
     */
    public function rendering()
    {
        $renderer = new TextRenderer();
        $output = new StreamOutput(fopen('php://memory', 'w', false));
        $rows = array(array('Column1' => 'Value A1', 'Column2' => 'A2 is another value that there is'), array(1, "multi\nline\nftw"), array("C1 cell here!", new \SimpleXMLElement('<r>PHP Magic->toString() test</r>')));
        $expected = '+---------------+-----------------------------------+
| Column1       | Column2                           |
+---------------+-----------------------------------+
| Value A1      | A2 is another value that there is |
| 1             | multi                             |
|               | line                              |
|               | ftw                               |
| C1 cell here! | PHP Magic->toString() test        |
+---------------+-----------------------------------+' . "\n";
        $renderer->render($output, $rows);
        $this->assertEquals($expected, $this->getOutputBuffer($output));
    }
TextRenderer