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:----MdhWhfXt0yZ+pN/4pSk24XHMJpsybCK7OZWp0pESdWE5xyi73zsI/zwXRyP96Ocd61rOPRc8aKX67IpsVRMF6rzyEGiVMLKy87nXSsGptAK5b6QM4uyj0NaRXtiBXRrLBjct7yvokv0Vmcfu3rhtp53aGul+SUgguTwF7125nSq19H7G5CBxORQWHXy8FxDS0N058LkMsZxQuI/ucidjWtfDNctclO0vDgVbpWtV2D2dLmIAVQDXqlJuhNZ7jS/tl4Cua62bAbQnzX1+vPfG1bF/RyJTny71j88JttC77cNDWaN7Sn4PVCTgnZVWljzjx9KiA9BFgTPBXk/nzM1dxyLFisNryTkJN9wS+SpWbYYF7WKpI+WAyIqpfJWN/GksrBiszn2ktUZCVw+FLh0QSB0IOqPUB446r2EVoi01LCeTo+aukXAFAff4k5hYblDs79mlnXq+Pdvy+xzYNssiVJSnzOhQFB6t5v3zjIfXCFxXEun8HETJZZML//y3ZnQTmBRrWHet36Otc39XLT+qlLSK42YJAq7P2JQwcjGjKeGMn3ZSybyAPcb4jJuDUY6LvEmcEy3EFXpQZV4ZFn0YdYKNVthwl6HrAsjwzDD9+s7ASspkUOzf827EOafRNoSEtQxxm2AArA0QbExCKLU0aKTiIVRpRdeC61ZUY/hHsUI=----ATTACHMENT:----ODM2OTY0NDQzMjg2NDkwOSAyMTQzNDMxNjAzMjU5ODQ1IDExNDc0NjA2NDYyMzE2MjI=