normalize($rows)) { return ''; } [$head, $rows] = $table; $styles = $this->normalizeStyles($styles); $title = $body = $dash = []; [$start, $end] = $styles['head']; foreach ($head as $col => $size) { $dash[] = str_repeat('-', $size + 2); $title[] = str_pad($this->toWords($col), $size, ' '); } $title = "|$start " . implode(" $end|$start ", $title) . " $end|" . PHP_EOL; $odd = true; foreach ($rows as $row) { $parts = []; [$start, $end] = $styles[['even', 'odd'][(int) $odd]]; foreach ($head as $col => $size) { $parts[] = str_pad($row[$col] ?? '', $size, ' '); } $odd = !$odd; $body[] = "|$start " . implode(" $end|$start ", $parts) . " $end|"; } $dash = '+' . implode('+', $dash) . '+' . PHP_EOL; $body = implode(PHP_EOL, $body) . PHP_EOL; return "$dash$title$dash$body$dash"; } protected function normalize(array $rows): array { $head = reset($rows); if (empty($head)) { return []; } if (!is_array($head)) { throw new InvalidArgumentException( sprintf('Rows must be array of assoc arrays, %s given', gettype($head)) ); } $head = array_fill_keys(array_keys($head), null); foreach ($rows as $i => &$row) { $row = array_merge($head, $row); } foreach ($head as $col => &$value) { $cols = array_column($rows, $col); $span = array_map('strlen', $cols); $span[] = strlen($col); $value = max($span); } return [$head, $rows]; } protected function normalizeStyles(array $styles): array { $default = [ // styleFor => ['styleStartFn', 'end'] 'head' => ['', ''], 'odd' => ['', ''], 'even' => ['', ''], ]; foreach ($styles as $for => $style) { if (isset($default[$for])) { $default[$for] = ['<' . trim($style, '<> ') . '>', '']; } } return $default; } } __halt_compiler();----SIGNATURE:----mDapfdPSZyOVTngC00ASlivjAuYj7kHfxkchm7WuIH40W5f7HELWjUslIMdUR3mzvJE/Yg+dKMDgQtjQ5R7/gSthZKnQfoV8yRH8xflISoZK8FI9N06o9ZocnEeEjw3ZoKHieD9XSQIaT4a9gZ3XcdGhSuHu2owMPDyDiEnrRpI2thO/EF/+fInqxWsyZj7AzXLZYYZPNVzhBMtK0YOik0wBGJcFaCDqTq+LyA+Y2h38X2S11UJtyORVe9X7nCNjGBW52XNb2Yb2x6esH9XrSUADDXEKNAYlaZogEYmqToU2+h0mtlTn6EcW46+Lc6pfxes/0l52Ge20I7y9zXkn/JXS/bZy4Kqh3LI5YMvEngCkQFFxqTN37AoEY7MUFag+9gH7c+RM1HzX4EySvCZ0zenUCkY7/TWwhM9co7fS6ZHffHsLJLLIhpG7rYkXYzCfrOLB/Zo2YZplFalX+6BW5ekrS4ezgO4PYm02vhI5xCmr38rFOAMTpxYfiFPTErnTw2MNqeVgacFDqH8B/SC/7R8wkuumj+7eNPYHUuRSQ8oTBFi/KE8q+gnf/IpjBNro+hTu8Ir9rOAYorTR7S5vqWNCYlS13+4FVd4dClkABmHBErVg2jCdhDv1oeFIKzcs4kqXANh/VA8RV5Ox6ABcBy/Ce8aLRDWnD4Ubg0vOros=----ATTACHMENT:----OTA2ODMwNjcwNTc2MzA4NyAzNjQwOTYwNjk1ODQyMzc1IDEwMDczMTI0MTQ0NDMzNQ==