4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Helper;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Output\NullOutput;
16 use Symfony\Component\Console\Exception\InvalidArgumentException;
19 * Provides helpers to display table output.
21 * @author Саша Стаменковић <umpirsky@gmail.com>
22 * @author Fabien Potencier <fabien@symfony.com>
24 * @deprecated since version 2.5, to be removed in 3.0
25 * Use {@link Table} instead.
27 class TableHelper extends Helper
29 const LAYOUT_DEFAULT = 0;
30 const LAYOUT_BORDERLESS = 1;
31 const LAYOUT_COMPACT = 2;
38 public function __construct($triggerDeprecationError = true)
40 if ($triggerDeprecationError) {
41 @trigger_error('The '.__CLASS__.' class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Console\Helper\Table class instead.', E_USER_DEPRECATED);
44 $this->table = new Table(new NullOutput());
48 * Sets table layout type.
50 * @param int $layout self::LAYOUT_*
54 * @throws InvalidArgumentException when the table layout is not known
56 public function setLayout($layout)
59 case self::LAYOUT_BORDERLESS:
60 $this->table->setStyle('borderless');
63 case self::LAYOUT_COMPACT:
64 $this->table->setStyle('compact');
67 case self::LAYOUT_DEFAULT:
68 $this->table->setStyle('default');
72 throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
78 public function setHeaders(array $headers)
80 $this->table->setHeaders($headers);
85 public function setRows(array $rows)
87 $this->table->setRows($rows);
92 public function addRows(array $rows)
94 $this->table->addRows($rows);
99 public function addRow(array $row)
101 $this->table->addRow($row);
106 public function setRow($column, array $row)
108 $this->table->setRow($column, $row);
114 * Sets padding character, used for cell padding.
116 * @param string $paddingChar
120 public function setPaddingChar($paddingChar)
122 $this->table->getStyle()->setPaddingChar($paddingChar);
128 * Sets horizontal border character.
130 * @param string $horizontalBorderChar
134 public function setHorizontalBorderChar($horizontalBorderChar)
136 $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
142 * Sets vertical border character.
144 * @param string $verticalBorderChar
148 public function setVerticalBorderChar($verticalBorderChar)
150 $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
156 * Sets crossing character.
158 * @param string $crossingChar
162 public function setCrossingChar($crossingChar)
164 $this->table->getStyle()->setCrossingChar($crossingChar);
170 * Sets header cell format.
172 * @param string $cellHeaderFormat
176 public function setCellHeaderFormat($cellHeaderFormat)
178 $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
184 * Sets row cell format.
186 * @param string $cellRowFormat
190 public function setCellRowFormat($cellRowFormat)
192 $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
198 * Sets row cell content format.
200 * @param string $cellRowContentFormat
204 public function setCellRowContentFormat($cellRowContentFormat)
206 $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
212 * Sets table border format.
214 * @param string $borderFormat
218 public function setBorderFormat($borderFormat)
220 $this->table->getStyle()->setBorderFormat($borderFormat);
226 * Sets cell padding type.
228 * @param int $padType STR_PAD_*
232 public function setPadType($padType)
234 $this->table->getStyle()->setPadType($padType);
240 * Renders table to output.
243 * +---------------+-----------------------+------------------+
244 * | ISBN | Title | Author |
245 * +---------------+-----------------------+------------------+
246 * | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
247 * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
248 * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
249 * +---------------+-----------------------+------------------+
251 * @param OutputInterface $output
253 public function render(OutputInterface $output)
255 $p = new \ReflectionProperty($this->table, 'output');
256 $p->setAccessible(true);
257 $p->setValue($this->table, $output);
259 $this->table->render();
265 public function getName()