123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\Console\Helper;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Output\NullOutput;
- use Symfony\Component\Console\Exception\InvalidArgumentException;
- /**
- * Provides helpers to display table output.
- *
- * @author Саша Стаменковић <umpirsky@gmail.com>
- * @author Fabien Potencier <fabien@symfony.com>
- *
- * @deprecated since version 2.5, to be removed in 3.0
- * Use {@link Table} instead.
- */
- class TableHelper extends Helper
- {
- const LAYOUT_DEFAULT = 0;
- const LAYOUT_BORDERLESS = 1;
- const LAYOUT_COMPACT = 2;
- /**
- * @var Table
- */
- private $table;
- public function __construct($triggerDeprecationError = true)
- {
- if ($triggerDeprecationError) {
- @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);
- }
- $this->table = new Table(new NullOutput());
- }
- /**
- * Sets table layout type.
- *
- * @param int $layout self::LAYOUT_*
- *
- * @return $this
- *
- * @throws InvalidArgumentException when the table layout is not known
- */
- public function setLayout($layout)
- {
- switch ($layout) {
- case self::LAYOUT_BORDERLESS:
- $this->table->setStyle('borderless');
- break;
- case self::LAYOUT_COMPACT:
- $this->table->setStyle('compact');
- break;
- case self::LAYOUT_DEFAULT:
- $this->table->setStyle('default');
- break;
- default:
- throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
- }
- return $this;
- }
- public function setHeaders(array $headers)
- {
- $this->table->setHeaders($headers);
- return $this;
- }
- public function setRows(array $rows)
- {
- $this->table->setRows($rows);
- return $this;
- }
- public function addRows(array $rows)
- {
- $this->table->addRows($rows);
- return $this;
- }
- public function addRow(array $row)
- {
- $this->table->addRow($row);
- return $this;
- }
- public function setRow($column, array $row)
- {
- $this->table->setRow($column, $row);
- return $this;
- }
- /**
- * Sets padding character, used for cell padding.
- *
- * @param string $paddingChar
- *
- * @return $this
- */
- public function setPaddingChar($paddingChar)
- {
- $this->table->getStyle()->setPaddingChar($paddingChar);
- return $this;
- }
- /**
- * Sets horizontal border character.
- *
- * @param string $horizontalBorderChar
- *
- * @return $this
- */
- public function setHorizontalBorderChar($horizontalBorderChar)
- {
- $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
- return $this;
- }
- /**
- * Sets vertical border character.
- *
- * @param string $verticalBorderChar
- *
- * @return $this
- */
- public function setVerticalBorderChar($verticalBorderChar)
- {
- $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
- return $this;
- }
- /**
- * Sets crossing character.
- *
- * @param string $crossingChar
- *
- * @return $this
- */
- public function setCrossingChar($crossingChar)
- {
- $this->table->getStyle()->setCrossingChar($crossingChar);
- return $this;
- }
- /**
- * Sets header cell format.
- *
- * @param string $cellHeaderFormat
- *
- * @return $this
- */
- public function setCellHeaderFormat($cellHeaderFormat)
- {
- $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
- return $this;
- }
- /**
- * Sets row cell format.
- *
- * @param string $cellRowFormat
- *
- * @return $this
- */
- public function setCellRowFormat($cellRowFormat)
- {
- $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
- return $this;
- }
- /**
- * Sets row cell content format.
- *
- * @param string $cellRowContentFormat
- *
- * @return $this
- */
- public function setCellRowContentFormat($cellRowContentFormat)
- {
- $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
- return $this;
- }
- /**
- * Sets table border format.
- *
- * @param string $borderFormat
- *
- * @return $this
- */
- public function setBorderFormat($borderFormat)
- {
- $this->table->getStyle()->setBorderFormat($borderFormat);
- return $this;
- }
- /**
- * Sets cell padding type.
- *
- * @param int $padType STR_PAD_*
- *
- * @return $this
- */
- public function setPadType($padType)
- {
- $this->table->getStyle()->setPadType($padType);
- return $this;
- }
- /**
- * Renders table to output.
- *
- * Example:
- * +---------------+-----------------------+------------------+
- * | ISBN | Title | Author |
- * +---------------+-----------------------+------------------+
- * | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
- * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
- * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
- * +---------------+-----------------------+------------------+
- *
- * @param OutputInterface $output
- */
- public function render(OutputInterface $output)
- {
- $p = new \ReflectionProperty($this->table, 'output');
- $p->setAccessible(true);
- $p->setValue($this->table, $output);
- $this->table->render();
- }
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return 'table';
- }
- }
|