TYPO3  7.6
TableHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Helper;
13 
16 
26 class TableHelper extends Helper
27 {
28  const LAYOUT_DEFAULT = 0;
29  const LAYOUT_BORDERLESS = 1;
30  const LAYOUT_COMPACT = 2;
31 
35  private $table;
36 
37  public function __construct($triggerDeprecationError = true)
38  {
39  if ($triggerDeprecationError) {
40  @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);
41  }
42 
43  $this->table = new Table(new NullOutput());
44  }
45 
55  public function setLayout($layout)
56  {
57  switch ($layout) {
58  case self::LAYOUT_BORDERLESS:
59  $this->table->setStyle('borderless');
60  break;
61 
62  case self::LAYOUT_COMPACT:
63  $this->table->setStyle('compact');
64  break;
65 
66  case self::LAYOUT_DEFAULT:
67  $this->table->setStyle('default');
68  break;
69 
70  default:
71  throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
72  };
73 
74  return $this;
75  }
76 
77  public function setHeaders(array $headers)
78  {
79  $this->table->setHeaders($headers);
80 
81  return $this;
82  }
83 
84  public function setRows(array $rows)
85  {
86  $this->table->setRows($rows);
87 
88  return $this;
89  }
90 
91  public function addRows(array $rows)
92  {
93  $this->table->addRows($rows);
94 
95  return $this;
96  }
97 
98  public function addRow(array $row)
99  {
100  $this->table->addRow($row);
101 
102  return $this;
103  }
104 
105  public function setRow($column, array $row)
106  {
107  $this->table->setRow($column, $row);
108 
109  return $this;
110  }
111 
119  public function setPaddingChar($paddingChar)
120  {
121  $this->table->getStyle()->setPaddingChar($paddingChar);
122 
123  return $this;
124  }
125 
133  public function setHorizontalBorderChar($horizontalBorderChar)
134  {
135  $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
136 
137  return $this;
138  }
139 
147  public function setVerticalBorderChar($verticalBorderChar)
148  {
149  $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
150 
151  return $this;
152  }
153 
161  public function setCrossingChar($crossingChar)
162  {
163  $this->table->getStyle()->setCrossingChar($crossingChar);
164 
165  return $this;
166  }
167 
175  public function setCellHeaderFormat($cellHeaderFormat)
176  {
177  $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
178 
179  return $this;
180  }
181 
189  public function setCellRowFormat($cellRowFormat)
190  {
191  $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
192 
193  return $this;
194  }
195 
203  public function setCellRowContentFormat($cellRowContentFormat)
204  {
205  $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
206 
207  return $this;
208  }
209 
217  public function setBorderFormat($borderFormat)
218  {
219  $this->table->getStyle()->setBorderFormat($borderFormat);
220 
221  return $this;
222  }
223 
231  public function setPadType($padType)
232  {
233  $this->table->getStyle()->setPadType($padType);
234 
235  return $this;
236  }
237 
252  public function render(OutputInterface $output)
253  {
254  $p = new \ReflectionProperty($this->table, 'output');
255  $p->setAccessible(true);
256  $p->setValue($this->table, $output);
257 
258  $this->table->render();
259  }
260 
264  public function getName()
265  {
266  return 'table';
267  }
268 }