Table.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Helper;
  11. use Symfony\Component\Console\Exception\InvalidArgumentException;
  12. use Symfony\Component\Console\Exception\RuntimeException;
  13. use Symfony\Component\Console\Output\ConsoleSectionOutput;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16. * Provides helpers to display a table.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Саша Стаменковић <umpirsky@gmail.com>
  20. * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
  21. * @author Max Grigorian <maxakawizard@gmail.com>
  22. * @author Dany Maillard <danymaillard93b@gmail.com>
  23. */
  24. class Table
  25. {
  26. private const SEPARATOR_TOP = 0;
  27. private const SEPARATOR_TOP_BOTTOM = 1;
  28. private const SEPARATOR_MID = 2;
  29. private const SEPARATOR_BOTTOM = 3;
  30. private const BORDER_OUTSIDE = 0;
  31. private const BORDER_INSIDE = 1;
  32. /**
  33. * Table headers.
  34. */
  35. private $headers = [];
  36. /**
  37. * Table rows.
  38. */
  39. private $rows = [];
  40. /**
  41. * Column widths cache.
  42. */
  43. private $effectiveColumnWidths = [];
  44. /**
  45. * Number of columns cache.
  46. *
  47. * @var int
  48. */
  49. private $numberOfColumns;
  50. /**
  51. * @var OutputInterface
  52. */
  53. private $output;
  54. /**
  55. * @var TableStyle
  56. */
  57. private $style;
  58. /**
  59. * @var array
  60. */
  61. private $columnStyles = [];
  62. /**
  63. * User set column widths.
  64. *
  65. * @var array
  66. */
  67. private $columnWidths = [];
  68. private static $styles;
  69. private $rendered = false;
  70. public function __construct(OutputInterface $output)
  71. {
  72. $this->output = $output;
  73. if (!self::$styles) {
  74. self::$styles = self::initStyles();
  75. }
  76. $this->setStyle('default');
  77. }
  78. /**
  79. * Sets a style definition.
  80. *
  81. * @param string $name The style name
  82. * @param TableStyle $style A TableStyle instance
  83. */
  84. public static function setStyleDefinition($name, TableStyle $style)
  85. {
  86. if (!self::$styles) {
  87. self::$styles = self::initStyles();
  88. }
  89. self::$styles[$name] = $style;
  90. }
  91. /**
  92. * Gets a style definition by name.
  93. *
  94. * @param string $name The style name
  95. *
  96. * @return TableStyle
  97. */
  98. public static function getStyleDefinition($name)
  99. {
  100. if (!self::$styles) {
  101. self::$styles = self::initStyles();
  102. }
  103. if (isset(self::$styles[$name])) {
  104. return self::$styles[$name];
  105. }
  106. throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  107. }
  108. /**
  109. * Sets table style.
  110. *
  111. * @param TableStyle|string $name The style name or a TableStyle instance
  112. *
  113. * @return $this
  114. */
  115. public function setStyle($name)
  116. {
  117. $this->style = $this->resolveStyle($name);
  118. return $this;
  119. }
  120. /**
  121. * Gets the current table style.
  122. *
  123. * @return TableStyle
  124. */
  125. public function getStyle()
  126. {
  127. return $this->style;
  128. }
  129. /**
  130. * Sets table column style.
  131. *
  132. * @param int $columnIndex Column index
  133. * @param TableStyle|string $name The style name or a TableStyle instance
  134. *
  135. * @return $this
  136. */
  137. public function setColumnStyle($columnIndex, $name)
  138. {
  139. $columnIndex = (int) $columnIndex;
  140. $this->columnStyles[$columnIndex] = $this->resolveStyle($name);
  141. return $this;
  142. }
  143. /**
  144. * Gets the current style for a column.
  145. *
  146. * If style was not set, it returns the global table style.
  147. *
  148. * @param int $columnIndex Column index
  149. *
  150. * @return TableStyle
  151. */
  152. public function getColumnStyle($columnIndex)
  153. {
  154. return $this->columnStyles[$columnIndex] ?? $this->getStyle();
  155. }
  156. /**
  157. * Sets the minimum width of a column.
  158. *
  159. * @param int $columnIndex Column index
  160. * @param int $width Minimum column width in characters
  161. *
  162. * @return $this
  163. */
  164. public function setColumnWidth($columnIndex, $width)
  165. {
  166. $this->columnWidths[(int) $columnIndex] = (int) $width;
  167. return $this;
  168. }
  169. /**
  170. * Sets the minimum width of all columns.
  171. *
  172. * @param array $widths
  173. *
  174. * @return $this
  175. */
  176. public function setColumnWidths(array $widths)
  177. {
  178. $this->columnWidths = [];
  179. foreach ($widths as $index => $width) {
  180. $this->setColumnWidth($index, $width);
  181. }
  182. return $this;
  183. }
  184. public function setHeaders(array $headers)
  185. {
  186. $headers = array_values($headers);
  187. if (!empty($headers) && !\is_array($headers[0])) {
  188. $headers = [$headers];
  189. }
  190. $this->headers = $headers;
  191. return $this;
  192. }
  193. public function setRows(array $rows)
  194. {
  195. $this->rows = [];
  196. return $this->addRows($rows);
  197. }
  198. public function addRows(array $rows)
  199. {
  200. foreach ($rows as $row) {
  201. $this->addRow($row);
  202. }
  203. return $this;
  204. }
  205. public function addRow($row)
  206. {
  207. if ($row instanceof TableSeparator) {
  208. $this->rows[] = $row;
  209. return $this;
  210. }
  211. if (!\is_array($row)) {
  212. throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.');
  213. }
  214. $this->rows[] = array_values($row);
  215. return $this;
  216. }
  217. /**
  218. * Adds a row to the table, and re-renders the table.
  219. */
  220. public function appendRow($row): self
  221. {
  222. if (!$this->output instanceof ConsoleSectionOutput) {
  223. throw new RuntimeException(sprintf('Output should be an instance of "%s" when calling "%s".', ConsoleSectionOutput::class, __METHOD__));
  224. }
  225. if ($this->rendered) {
  226. $this->output->clear($this->calculateRowCount());
  227. }
  228. $this->addRow($row);
  229. $this->render();
  230. return $this;
  231. }
  232. public function setRow($column, array $row)
  233. {
  234. $this->rows[$column] = $row;
  235. return $this;
  236. }
  237. /**
  238. * Renders table to output.
  239. *
  240. * Example:
  241. *
  242. * +---------------+-----------------------+------------------+
  243. * | ISBN | Title | Author |
  244. * +---------------+-----------------------+------------------+
  245. * | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
  246. * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
  247. * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
  248. * +---------------+-----------------------+------------------+
  249. */
  250. public function render()
  251. {
  252. $rows = array_merge($this->headers, [$divider = new TableSeparator()], $this->rows);
  253. $this->calculateNumberOfColumns($rows);
  254. $rows = $this->buildTableRows($rows);
  255. $this->calculateColumnsWidth($rows);
  256. $isHeader = true;
  257. $isFirstRow = false;
  258. foreach ($rows as $row) {
  259. if ($divider === $row) {
  260. $isHeader = false;
  261. $isFirstRow = true;
  262. continue;
  263. }
  264. if ($row instanceof TableSeparator) {
  265. $this->renderRowSeparator();
  266. continue;
  267. }
  268. if (!$row) {
  269. continue;
  270. }
  271. if ($isHeader || $isFirstRow) {
  272. $this->renderRowSeparator($isFirstRow ? self::SEPARATOR_TOP_BOTTOM : self::SEPARATOR_TOP);
  273. if ($isFirstRow) {
  274. $isFirstRow = false;
  275. }
  276. }
  277. $this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
  278. }
  279. $this->renderRowSeparator(self::SEPARATOR_BOTTOM);
  280. $this->cleanup();
  281. $this->rendered = true;
  282. }
  283. /**
  284. * Renders horizontal header separator.
  285. *
  286. * Example:
  287. *
  288. * +-----+-----------+-------+
  289. */
  290. private function renderRowSeparator(int $type = self::SEPARATOR_MID)
  291. {
  292. if (0 === $count = $this->numberOfColumns) {
  293. return;
  294. }
  295. $borders = $this->style->getBorderChars();
  296. if (!$borders[0] && !$borders[2] && !$this->style->getCrossingChar()) {
  297. return;
  298. }
  299. $crossings = $this->style->getCrossingChars();
  300. if (self::SEPARATOR_MID === $type) {
  301. list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[2], $crossings[8], $crossings[0], $crossings[4]];
  302. } elseif (self::SEPARATOR_TOP === $type) {
  303. list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[1], $crossings[2], $crossings[3]];
  304. } elseif (self::SEPARATOR_TOP_BOTTOM === $type) {
  305. list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[9], $crossings[10], $crossings[11]];
  306. } else {
  307. list($horizontal, $leftChar, $midChar, $rightChar) = [$borders[0], $crossings[7], $crossings[6], $crossings[5]];
  308. }
  309. $markup = $leftChar;
  310. for ($column = 0; $column < $count; ++$column) {
  311. $markup .= str_repeat($horizontal, $this->effectiveColumnWidths[$column]);
  312. $markup .= $column === $count - 1 ? $rightChar : $midChar;
  313. }
  314. $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
  315. }
  316. /**
  317. * Renders vertical column separator.
  318. */
  319. private function renderColumnSeparator($type = self::BORDER_OUTSIDE)
  320. {
  321. $borders = $this->style->getBorderChars();
  322. return sprintf($this->style->getBorderFormat(), self::BORDER_OUTSIDE === $type ? $borders[1] : $borders[3]);
  323. }
  324. /**
  325. * Renders table row.
  326. *
  327. * Example:
  328. *
  329. * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
  330. */
  331. private function renderRow(array $row, string $cellFormat)
  332. {
  333. $rowContent = $this->renderColumnSeparator(self::BORDER_OUTSIDE);
  334. $columns = $this->getRowColumns($row);
  335. $last = \count($columns) - 1;
  336. foreach ($columns as $i => $column) {
  337. $rowContent .= $this->renderCell($row, $column, $cellFormat);
  338. $rowContent .= $this->renderColumnSeparator($last === $i ? self::BORDER_OUTSIDE : self::BORDER_INSIDE);
  339. }
  340. $this->output->writeln($rowContent);
  341. }
  342. /**
  343. * Renders table cell with padding.
  344. */
  345. private function renderCell(array $row, int $column, string $cellFormat)
  346. {
  347. $cell = isset($row[$column]) ? $row[$column] : '';
  348. $width = $this->effectiveColumnWidths[$column];
  349. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  350. // add the width of the following columns(numbers of colspan).
  351. foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) {
  352. $width += $this->getColumnSeparatorWidth() + $this->effectiveColumnWidths[$nextColumn];
  353. }
  354. }
  355. // str_pad won't work properly with multi-byte strings, we need to fix the padding
  356. if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
  357. $width += \strlen($cell) - mb_strwidth($cell, $encoding);
  358. }
  359. $style = $this->getColumnStyle($column);
  360. if ($cell instanceof TableSeparator) {
  361. return sprintf($style->getBorderFormat(), str_repeat($style->getBorderChars()[2], $width));
  362. }
  363. $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
  364. $content = sprintf($style->getCellRowContentFormat(), $cell);
  365. return sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType()));
  366. }
  367. /**
  368. * Calculate number of columns for this table.
  369. */
  370. private function calculateNumberOfColumns($rows)
  371. {
  372. $columns = [0];
  373. foreach ($rows as $row) {
  374. if ($row instanceof TableSeparator) {
  375. continue;
  376. }
  377. $columns[] = $this->getNumberOfColumns($row);
  378. }
  379. $this->numberOfColumns = max($columns);
  380. }
  381. private function buildTableRows($rows)
  382. {
  383. $unmergedRows = [];
  384. for ($rowKey = 0; $rowKey < \count($rows); ++$rowKey) {
  385. $rows = $this->fillNextRows($rows, $rowKey);
  386. // Remove any new line breaks and replace it with a new line
  387. foreach ($rows[$rowKey] as $column => $cell) {
  388. if (!strstr($cell, "\n")) {
  389. continue;
  390. }
  391. $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
  392. foreach ($lines as $lineKey => $line) {
  393. if ($cell instanceof TableCell) {
  394. $line = new TableCell($line, ['colspan' => $cell->getColspan()]);
  395. }
  396. if (0 === $lineKey) {
  397. $rows[$rowKey][$column] = $line;
  398. } else {
  399. $unmergedRows[$rowKey][$lineKey][$column] = $line;
  400. }
  401. }
  402. }
  403. }
  404. return new TableRows(function () use ($rows, $unmergedRows) {
  405. foreach ($rows as $rowKey => $row) {
  406. yield $this->fillCells($row);
  407. if (isset($unmergedRows[$rowKey])) {
  408. foreach ($unmergedRows[$rowKey] as $row) {
  409. yield $row;
  410. }
  411. }
  412. }
  413. });
  414. }
  415. private function calculateRowCount(): int
  416. {
  417. $numberOfRows = \count(iterator_to_array($this->buildTableRows(array_merge($this->headers, [new TableSeparator()], $this->rows))));
  418. if ($this->headers) {
  419. ++$numberOfRows; // Add row for header separator
  420. }
  421. ++$numberOfRows; // Add row for footer separator
  422. return $numberOfRows;
  423. }
  424. /**
  425. * fill rows that contains rowspan > 1.
  426. *
  427. * @throws InvalidArgumentException
  428. */
  429. private function fillNextRows(array $rows, int $line): array
  430. {
  431. $unmergedRows = [];
  432. foreach ($rows[$line] as $column => $cell) {
  433. if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) {
  434. throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing __toString, %s given.', \gettype($cell)));
  435. }
  436. if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
  437. $nbLines = $cell->getRowspan() - 1;
  438. $lines = [$cell];
  439. if (strstr($cell, "\n")) {
  440. $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
  441. $nbLines = \count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
  442. $rows[$line][$column] = new TableCell($lines[0], ['colspan' => $cell->getColspan()]);
  443. unset($lines[0]);
  444. }
  445. // create a two dimensional array (rowspan x colspan)
  446. $unmergedRows = array_replace_recursive(array_fill($line + 1, $nbLines, []), $unmergedRows);
  447. foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
  448. $value = isset($lines[$unmergedRowKey - $line]) ? $lines[$unmergedRowKey - $line] : '';
  449. $unmergedRows[$unmergedRowKey][$column] = new TableCell($value, ['colspan' => $cell->getColspan()]);
  450. if ($nbLines === $unmergedRowKey - $line) {
  451. break;
  452. }
  453. }
  454. }
  455. }
  456. foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
  457. // we need to know if $unmergedRow will be merged or inserted into $rows
  458. if (isset($rows[$unmergedRowKey]) && \is_array($rows[$unmergedRowKey]) && ($this->getNumberOfColumns($rows[$unmergedRowKey]) + $this->getNumberOfColumns($unmergedRows[$unmergedRowKey]) <= $this->numberOfColumns)) {
  459. foreach ($unmergedRow as $cellKey => $cell) {
  460. // insert cell into row at cellKey position
  461. array_splice($rows[$unmergedRowKey], $cellKey, 0, [$cell]);
  462. }
  463. } else {
  464. $row = $this->copyRow($rows, $unmergedRowKey - 1);
  465. foreach ($unmergedRow as $column => $cell) {
  466. if (!empty($cell)) {
  467. $row[$column] = $unmergedRow[$column];
  468. }
  469. }
  470. array_splice($rows, $unmergedRowKey, 0, [$row]);
  471. }
  472. }
  473. return $rows;
  474. }
  475. /**
  476. * fill cells for a row that contains colspan > 1.
  477. */
  478. private function fillCells($row)
  479. {
  480. $newRow = [];
  481. foreach ($row as $column => $cell) {
  482. $newRow[] = $cell;
  483. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  484. foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
  485. // insert empty value at column position
  486. $newRow[] = '';
  487. }
  488. }
  489. }
  490. return $newRow ?: $row;
  491. }
  492. private function copyRow(array $rows, int $line): array
  493. {
  494. $row = $rows[$line];
  495. foreach ($row as $cellKey => $cellValue) {
  496. $row[$cellKey] = '';
  497. if ($cellValue instanceof TableCell) {
  498. $row[$cellKey] = new TableCell('', ['colspan' => $cellValue->getColspan()]);
  499. }
  500. }
  501. return $row;
  502. }
  503. /**
  504. * Gets number of columns by row.
  505. */
  506. private function getNumberOfColumns(array $row): int
  507. {
  508. $columns = \count($row);
  509. foreach ($row as $column) {
  510. $columns += $column instanceof TableCell ? ($column->getColspan() - 1) : 0;
  511. }
  512. return $columns;
  513. }
  514. /**
  515. * Gets list of columns for the given row.
  516. */
  517. private function getRowColumns(array $row): array
  518. {
  519. $columns = range(0, $this->numberOfColumns - 1);
  520. foreach ($row as $cellKey => $cell) {
  521. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  522. // exclude grouped columns.
  523. $columns = array_diff($columns, range($cellKey + 1, $cellKey + $cell->getColspan() - 1));
  524. }
  525. }
  526. return $columns;
  527. }
  528. /**
  529. * Calculates columns widths.
  530. */
  531. private function calculateColumnsWidth(iterable $rows)
  532. {
  533. for ($column = 0; $column < $this->numberOfColumns; ++$column) {
  534. $lengths = [];
  535. foreach ($rows as $row) {
  536. if ($row instanceof TableSeparator) {
  537. continue;
  538. }
  539. foreach ($row as $i => $cell) {
  540. if ($cell instanceof TableCell) {
  541. $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
  542. $textLength = Helper::strlen($textContent);
  543. if ($textLength > 0) {
  544. $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
  545. foreach ($contentColumns as $position => $content) {
  546. $row[$i + $position] = $content;
  547. }
  548. }
  549. }
  550. }
  551. $lengths[] = $this->getCellWidth($row, $column);
  552. }
  553. $this->effectiveColumnWidths[$column] = max($lengths) + Helper::strlen($this->style->getCellRowContentFormat()) - 2;
  554. }
  555. }
  556. private function getColumnSeparatorWidth(): int
  557. {
  558. return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getBorderChars()[3]));
  559. }
  560. private function getCellWidth(array $row, int $column): int
  561. {
  562. $cellWidth = 0;
  563. if (isset($row[$column])) {
  564. $cell = $row[$column];
  565. $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
  566. }
  567. $columnWidth = isset($this->columnWidths[$column]) ? $this->columnWidths[$column] : 0;
  568. return max($cellWidth, $columnWidth);
  569. }
  570. /**
  571. * Called after rendering to cleanup cache data.
  572. */
  573. private function cleanup()
  574. {
  575. $this->effectiveColumnWidths = [];
  576. $this->numberOfColumns = null;
  577. }
  578. private static function initStyles()
  579. {
  580. $borderless = new TableStyle();
  581. $borderless
  582. ->setHorizontalBorderChars('=')
  583. ->setVerticalBorderChars(' ')
  584. ->setDefaultCrossingChar(' ')
  585. ;
  586. $compact = new TableStyle();
  587. $compact
  588. ->setHorizontalBorderChars('')
  589. ->setVerticalBorderChars(' ')
  590. ->setDefaultCrossingChar('')
  591. ->setCellRowContentFormat('%s')
  592. ;
  593. $styleGuide = new TableStyle();
  594. $styleGuide
  595. ->setHorizontalBorderChars('-')
  596. ->setVerticalBorderChars(' ')
  597. ->setDefaultCrossingChar(' ')
  598. ->setCellHeaderFormat('%s')
  599. ;
  600. $box = (new TableStyle())
  601. ->setHorizontalBorderChars('─')
  602. ->setVerticalBorderChars('│')
  603. ->setCrossingChars('┼', '┌', '┬', '┐', '┤', '┘', '┴', '└', '├')
  604. ;
  605. $boxDouble = (new TableStyle())
  606. ->setHorizontalBorderChars('═', '─')
  607. ->setVerticalBorderChars('║', '│')
  608. ->setCrossingChars('┼', '╔', '╤', '╗', '╢', '╝', '╧', '╚', '╟', '╠', '╪', '╣')
  609. ;
  610. return [
  611. 'default' => new TableStyle(),
  612. 'borderless' => $borderless,
  613. 'compact' => $compact,
  614. 'symfony-style-guide' => $styleGuide,
  615. 'box' => $box,
  616. 'box-double' => $boxDouble,
  617. ];
  618. }
  619. private function resolveStyle($name)
  620. {
  621. if ($name instanceof TableStyle) {
  622. return $name;
  623. }
  624. if (isset(self::$styles[$name])) {
  625. return self::$styles[$name];
  626. }
  627. throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  628. }
  629. }