Table.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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\Output\ConsoleSectionOutput;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. use Symfony\Component\Console\Exception\InvalidArgumentException;
  14. use Symfony\Component\Console\Exception\RuntimeException;
  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 = array();
  36. /**
  37. * Table rows.
  38. */
  39. private $rows = array();
  40. /**
  41. * Column widths cache.
  42. */
  43. private $effectiveColumnWidths = array();
  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 = array();
  62. /**
  63. * User set column widths.
  64. *
  65. * @var array
  66. */
  67. private $columnWidths = array();
  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. if (isset($this->columnStyles[$columnIndex])) {
  155. return $this->columnStyles[$columnIndex];
  156. }
  157. return $this->getStyle();
  158. }
  159. /**
  160. * Sets the minimum width of a column.
  161. *
  162. * @param int $columnIndex Column index
  163. * @param int $width Minimum column width in characters
  164. *
  165. * @return $this
  166. */
  167. public function setColumnWidth($columnIndex, $width)
  168. {
  169. $this->columnWidths[(int) $columnIndex] = (int) $width;
  170. return $this;
  171. }
  172. /**
  173. * Sets the minimum width of all columns.
  174. *
  175. * @param array $widths
  176. *
  177. * @return $this
  178. */
  179. public function setColumnWidths(array $widths)
  180. {
  181. $this->columnWidths = array();
  182. foreach ($widths as $index => $width) {
  183. $this->setColumnWidth($index, $width);
  184. }
  185. return $this;
  186. }
  187. public function setHeaders(array $headers)
  188. {
  189. $headers = array_values($headers);
  190. if (!empty($headers) && !is_array($headers[0])) {
  191. $headers = array($headers);
  192. }
  193. $this->headers = $headers;
  194. return $this;
  195. }
  196. public function setRows(array $rows)
  197. {
  198. $this->rows = array();
  199. return $this->addRows($rows);
  200. }
  201. public function addRows(array $rows)
  202. {
  203. foreach ($rows as $row) {
  204. $this->addRow($row);
  205. }
  206. return $this;
  207. }
  208. public function addRow($row)
  209. {
  210. if ($row instanceof TableSeparator) {
  211. $this->rows[] = $row;
  212. return $this;
  213. }
  214. if (!is_array($row)) {
  215. throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.');
  216. }
  217. $this->rows[] = array_values($row);
  218. return $this;
  219. }
  220. /**
  221. * Adds a row to the table, and re-renders the table.
  222. */
  223. public function appendRow($row): self
  224. {
  225. if (!$this->output instanceof ConsoleSectionOutput) {
  226. throw new RuntimeException(sprintf('Output should be an instance of "%s" when calling "%s".', ConsoleSectionOutput::class, __METHOD__));
  227. }
  228. if ($this->rendered) {
  229. $this->output->clear($this->calculateRowCount());
  230. }
  231. $this->addRow($row);
  232. $this->render();
  233. return $this;
  234. }
  235. public function setRow($column, array $row)
  236. {
  237. $this->rows[$column] = $row;
  238. return $this;
  239. }
  240. /**
  241. * Renders table to output.
  242. *
  243. * Example:
  244. * <code>
  245. * +---------------+-----------------------+------------------+
  246. * | ISBN | Title | Author |
  247. * +---------------+-----------------------+------------------+
  248. * | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
  249. * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
  250. * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
  251. * +---------------+-----------------------+------------------+
  252. * </code>
  253. */
  254. public function render()
  255. {
  256. $rows = array_merge($this->headers, array($divider = new TableSeparator()), $this->rows);
  257. $this->calculateNumberOfColumns($rows);
  258. $rows = $this->buildTableRows($rows);
  259. $this->calculateColumnsWidth($rows);
  260. $isHeader = true;
  261. $isFirstRow = false;
  262. foreach ($rows as $row) {
  263. if ($divider === $row) {
  264. $isHeader = false;
  265. $isFirstRow = true;
  266. continue;
  267. }
  268. if ($row instanceof TableSeparator) {
  269. $this->renderRowSeparator();
  270. continue;
  271. }
  272. if (!$row) {
  273. continue;
  274. }
  275. if ($isHeader || $isFirstRow) {
  276. $this->renderRowSeparator($isFirstRow ? self::SEPARATOR_TOP_BOTTOM : self::SEPARATOR_TOP);
  277. if ($isFirstRow) {
  278. $isFirstRow = false;
  279. }
  280. }
  281. $this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
  282. }
  283. $this->renderRowSeparator(self::SEPARATOR_BOTTOM);
  284. $this->cleanup();
  285. $this->rendered = true;
  286. }
  287. /**
  288. * Renders horizontal header separator.
  289. *
  290. * Example: <code>+-----+-----------+-------+</code>
  291. */
  292. private function renderRowSeparator(int $type = self::SEPARATOR_MID)
  293. {
  294. if (0 === $count = $this->numberOfColumns) {
  295. return;
  296. }
  297. $borders = $this->style->getBorderChars();
  298. if (!$borders[0] && !$borders[2] && !$this->style->getCrossingChar()) {
  299. return;
  300. }
  301. $crossings = $this->style->getCrossingChars();
  302. if (self::SEPARATOR_MID === $type) {
  303. list($horizontal, $leftChar, $midChar, $rightChar) = array($borders[2], $crossings[8], $crossings[0], $crossings[4]);
  304. } elseif (self::SEPARATOR_TOP === $type) {
  305. list($horizontal, $leftChar, $midChar, $rightChar) = array($borders[0], $crossings[1], $crossings[2], $crossings[3]);
  306. } elseif (self::SEPARATOR_TOP_BOTTOM === $type) {
  307. list($horizontal, $leftChar, $midChar, $rightChar) = array($borders[0], $crossings[9], $crossings[10], $crossings[11]);
  308. } else {
  309. list($horizontal, $leftChar, $midChar, $rightChar) = array($borders[0], $crossings[7], $crossings[6], $crossings[5]);
  310. }
  311. $markup = $leftChar;
  312. for ($column = 0; $column < $count; ++$column) {
  313. $markup .= str_repeat($horizontal, $this->effectiveColumnWidths[$column]);
  314. $markup .= $column === $count - 1 ? $rightChar : $midChar;
  315. }
  316. $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
  317. }
  318. /**
  319. * Renders vertical column separator.
  320. */
  321. private function renderColumnSeparator($type = self::BORDER_OUTSIDE)
  322. {
  323. $borders = $this->style->getBorderChars();
  324. return sprintf($this->style->getBorderFormat(), self::BORDER_OUTSIDE === $type ? $borders[1] : $borders[3]);
  325. }
  326. /**
  327. * Renders table row.
  328. *
  329. * Example: <code>| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |</code>
  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 = array(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 = array();
  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, array('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, array(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 = array();
  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 = array($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], array('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, array()), $unmergedRows);
  447. foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
  448. $value = isset($lines[$unmergedRowKey - $line]) ? $lines[$unmergedRowKey - $line] : '';
  449. $unmergedRows[$unmergedRowKey][$column] = new TableCell($value, array('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, array($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, array($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 = array();
  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('', array('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 = array();
  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) + strlen($this->style->getCellRowContentFormat()) - 2;
  554. }
  555. }
  556. private function getColumnSeparatorWidth(): int
  557. {
  558. return 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 = array();
  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 array(
  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. }