123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- namespace Symfony\Component\Console\Helper;
- use Symfony\Component\Console\Exception\InvalidArgumentException;
- use Symfony\Component\Console\Output\NullOutput;
- use Symfony\Component\Console\Output\OutputInterface;
- class TableHelper extends Helper
- {
- const LAYOUT_DEFAULT = 0;
- const LAYOUT_BORDERLESS = 1;
- const LAYOUT_COMPACT = 2;
- private $table;
- public function __construct($triggerDeprecationError = true)
- {
- if ($triggerDeprecationError) {
- @trigger_error('The '.__CLASS__.' class is deprecated since Symfony 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());
- }
-
- 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;
- }
-
- public function setPaddingChar($paddingChar)
- {
- $this->table->getStyle()->setPaddingChar($paddingChar);
- return $this;
- }
-
- public function setHorizontalBorderChar($horizontalBorderChar)
- {
- $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
- return $this;
- }
-
- public function setVerticalBorderChar($verticalBorderChar)
- {
- $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
- return $this;
- }
-
- public function setCrossingChar($crossingChar)
- {
- $this->table->getStyle()->setCrossingChar($crossingChar);
- return $this;
- }
-
- public function setCellHeaderFormat($cellHeaderFormat)
- {
- $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
- return $this;
- }
-
- public function setCellRowFormat($cellRowFormat)
- {
- $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
- return $this;
- }
-
- public function setCellRowContentFormat($cellRowContentFormat)
- {
- $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
- return $this;
- }
-
- public function setBorderFormat($borderFormat)
- {
- $this->table->getStyle()->setBorderFormat($borderFormat);
- return $this;
- }
-
- public function setPadType($padType)
- {
- $this->table->getStyle()->setPadType($padType);
- return $this;
- }
-
- public function render(OutputInterface $output)
- {
- $p = new \ReflectionProperty($this->table, 'output');
- $p->setAccessible(true);
- $p->setValue($this->table, $output);
- $this->table->render();
- }
-
- public function getName()
- {
- return 'table';
- }
- }
|