setTable($table); } } /** * Returns the total number of rows in the table * * @return int */ public function totalRows(): int { return count($this->tableRows); } /** * Adds a table header * * @param array $header * @param string $style * @return void */ public function addHeader(array $header, $style = 'alt'): void { $this->insertTableRow($header, $style); } /** * Sets the table rows at once * * @param array $full_table An array containing each table row. Rows must be arrays containing the individual cell contents. * @return void */ public function setTable(array $full_table): void { $first = true; foreach ($full_table as $row) { if ($first) { $this->addHeader($row); $first = false; continue; } $this->addRow($row); } } /** * Adds a table row * * @param array $row * @param string $style * @return void */ public function addRow(array $row, string $style = 'default'): void { $this->insertTableRow($row, $style); } /** * Returns the formatted table for printing * * @param OutputFilterInterface|null $filter In case no filter is provided, a SimpleOutputFilter is used by default. * @return string */ public function getFormattedTable(OutputFilterInterface $filter = null): string { $filter = $filter ?? new SimpleOutputFilter(); foreach ($this->styledRows as $item) { $style = $item['style']; $row = $this->getRowAsString($item['row']); $this->formattedTable .= "\n" . $filter->filter($row, $style); } return $this->formattedTable; } /** * Inserts a new row in the table and sets the style for that row * * @param array $row * @param string $style * @return void */ protected function insertTableRow(array $row, string $style = 'default'): void { $this->tableRows[] = $row; $this->styledRows[] = [ 'row' => $row, 'style' => $style ]; } /** * Calculates ideal column sizes for the current table rows * * @param int $minColSize * @return array */ protected function calculateColumnSizes(int $minColSize = 5): array { $columnSizes = []; foreach ($this->tableRows as $rowContent) { $columnCount = 0; foreach ($rowContent as $cell) { $columnSizes[$columnCount] = $columnSizes[$columnCount] ?? $minColSize; if (strlen($cell) >= $columnSizes[$columnCount]) { $columnSizes[$columnCount] = strlen($cell) + 2; } $columnCount++; } } return $columnSizes; } /** * Transforms a row into a formatted string, with adequate column sizing * * @param array $row * @return string */ protected function getRowAsString(array $row): string { //first, determine the size of each column $columnSizes = $this->calculateColumnSizes(); $formattedRow = ""; foreach ($row as $column => $tableCell) { $formattedRow .= $this->getPaddedString($tableCell, $columnSizes[$column]); } return $formattedRow; } /** * Pads a string as table cell * * @param string $tableCell * @param int $colSize * @return string */ protected function getPaddedString(string $tableCell, int $colSize = 5): string { return str_pad($tableCell, $colSize); } } __halt_compiler();----SIGNATURE:----Qreh01sCjoXWQR+JdraZ6yHtHYpWE+tXOWAlBOZrR9s11mcmv8ca6amQr5QAKLSAxveN2BdbdIqDJufKW7b0FtKqrqhrxLUpn076UANPy7ZfISNdsobsDG5jtL0Nq+AygdyrriDhdoIhn/OGmf9DahyAXnucxqNZcoJsG3qQE7WKoUWYHEitrNmjp7PXaUafxptA7fROAfh/9CIkyk6LtgOWQibbtWgJZ5uYBBstQvB7wm+HKjyi3A/+OrSE4509smeh3+TGoDuBC2dvzdwgBO1dLQB0xJLEDdCHEiqsiDTvNZAM2L53lxCCisPCSACZrTMnIpCskPBhW6IYizT4aGocd8T7L/LjtyurQ3DqBVyyCZLtju6z2yePLoBs2YzAhZunsAEL7MeDu4oJO8htWd2Id56jhCZuXmXGXm2zM4noXIymfXkjq82BZjywwJFCkGHs0zkDOr3q5V5YIvPx8YTz+ct7eGCRlzSPbZmNgGwNtPEFRoMrxIw5Jy18wbL6aA/qhBLJMArXY31nz97UrHm0TKUrftz6vwazULZq1mEh5KH+VMm/A8nQ+GFn8OcmBxV5mk/Li5DTQr+0j3PLtipSbj2q4aLTLma48yj4Pd9jDEsZUDEtpnkJEUPGGtIS1pYHUDFkKaOeiykMGfHbr/jOFOGU3nY3uNWnuqS5L+M=----ATTACHMENT:----NDkxNzk0OTc3Mjk0MTc5OSAzMDQ3NTkzNTgwNTA5NjYxIDE4MDY2Njc5ODM3MTAzNjE=