(isset($widths[$i]) ? $widths[$i] : 0)) { $widths[$i] = $columnLength; } } } return $widths; } /** * Output a row separator. * * @param array $widths The widths of each column to output. * @return void */ protected function _rowSeparator($widths) { $out = ''; foreach ($widths as $column) { $out .= '+' . str_repeat('-', $column + 2); } $out .= '+'; $this->_io->out($out); } /** * Output a row. * * @param array $row The row to ouptut. * @param array $widths The widths of each column to output. * @return void */ protected function _render($row, $widths) { $out = ''; foreach ($row as $i => $column) { $pad = $widths[$i] - mb_strlen($column); $out .= '| ' . $column . str_repeat(' ', $pad) . ' '; } $out .= '|'; $this->_io->out($out); } /** * Output a table. * * @param array $rows The data to render out. * @return void */ public function output($rows) { if (count($rows) === 1) { $rows = $rows[0]; } $widths = $this->_calculateWidths($rows); $this->_rowSeparator($widths); $this->_render(array_shift($rows), $widths); $this->_rowSeparator($widths); foreach ($rows as $line) { $this->_render($line, $widths); } $this->_rowSeparator($widths); } }