Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Helper / TableHelper.php
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
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Output\NullOutput;
16 use Symfony\Component\Console\Exception\InvalidArgumentException;
17
18 /**
19  * Provides helpers to display table output.
20  *
21  * @author Саша Стаменковић <umpirsky@gmail.com>
22  * @author Fabien Potencier <fabien@symfony.com>
23  *
24  * @deprecated since version 2.5, to be removed in 3.0
25  *             Use {@link Table} instead.
26  */
27 class TableHelper extends Helper
28 {
29     const LAYOUT_DEFAULT = 0;
30     const LAYOUT_BORDERLESS = 1;
31     const LAYOUT_COMPACT = 2;
32
33     /**
34      * @var Table
35      */
36     private $table;
37
38     public function __construct($triggerDeprecationError = true)
39     {
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);
42         }
43
44         $this->table = new Table(new NullOutput());
45     }
46
47     /**
48      * Sets table layout type.
49      *
50      * @param int $layout self::LAYOUT_*
51      *
52      * @return $this
53      *
54      * @throws InvalidArgumentException when the table layout is not known
55      */
56     public function setLayout($layout)
57     {
58         switch ($layout) {
59             case self::LAYOUT_BORDERLESS:
60                 $this->table->setStyle('borderless');
61                 break;
62
63             case self::LAYOUT_COMPACT:
64                 $this->table->setStyle('compact');
65                 break;
66
67             case self::LAYOUT_DEFAULT:
68                 $this->table->setStyle('default');
69                 break;
70
71             default:
72                 throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
73         }
74
75         return $this;
76     }
77
78     public function setHeaders(array $headers)
79     {
80         $this->table->setHeaders($headers);
81
82         return $this;
83     }
84
85     public function setRows(array $rows)
86     {
87         $this->table->setRows($rows);
88
89         return $this;
90     }
91
92     public function addRows(array $rows)
93     {
94         $this->table->addRows($rows);
95
96         return $this;
97     }
98
99     public function addRow(array $row)
100     {
101         $this->table->addRow($row);
102
103         return $this;
104     }
105
106     public function setRow($column, array $row)
107     {
108         $this->table->setRow($column, $row);
109
110         return $this;
111     }
112
113     /**
114      * Sets padding character, used for cell padding.
115      *
116      * @param string $paddingChar
117      *
118      * @return $this
119      */
120     public function setPaddingChar($paddingChar)
121     {
122         $this->table->getStyle()->setPaddingChar($paddingChar);
123
124         return $this;
125     }
126
127     /**
128      * Sets horizontal border character.
129      *
130      * @param string $horizontalBorderChar
131      *
132      * @return $this
133      */
134     public function setHorizontalBorderChar($horizontalBorderChar)
135     {
136         $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
137
138         return $this;
139     }
140
141     /**
142      * Sets vertical border character.
143      *
144      * @param string $verticalBorderChar
145      *
146      * @return $this
147      */
148     public function setVerticalBorderChar($verticalBorderChar)
149     {
150         $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
151
152         return $this;
153     }
154
155     /**
156      * Sets crossing character.
157      *
158      * @param string $crossingChar
159      *
160      * @return $this
161      */
162     public function setCrossingChar($crossingChar)
163     {
164         $this->table->getStyle()->setCrossingChar($crossingChar);
165
166         return $this;
167     }
168
169     /**
170      * Sets header cell format.
171      *
172      * @param string $cellHeaderFormat
173      *
174      * @return $this
175      */
176     public function setCellHeaderFormat($cellHeaderFormat)
177     {
178         $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
179
180         return $this;
181     }
182
183     /**
184      * Sets row cell format.
185      *
186      * @param string $cellRowFormat
187      *
188      * @return $this
189      */
190     public function setCellRowFormat($cellRowFormat)
191     {
192         $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
193
194         return $this;
195     }
196
197     /**
198      * Sets row cell content format.
199      *
200      * @param string $cellRowContentFormat
201      *
202      * @return $this
203      */
204     public function setCellRowContentFormat($cellRowContentFormat)
205     {
206         $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
207
208         return $this;
209     }
210
211     /**
212      * Sets table border format.
213      *
214      * @param string $borderFormat
215      *
216      * @return $this
217      */
218     public function setBorderFormat($borderFormat)
219     {
220         $this->table->getStyle()->setBorderFormat($borderFormat);
221
222         return $this;
223     }
224
225     /**
226      * Sets cell padding type.
227      *
228      * @param int $padType STR_PAD_*
229      *
230      * @return $this
231      */
232     public function setPadType($padType)
233     {
234         $this->table->getStyle()->setPadType($padType);
235
236         return $this;
237     }
238
239     /**
240      * Renders table to output.
241      *
242      * Example:
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      * +---------------+-----------------------+------------------+
250      *
251      * @param OutputInterface $output
252      */
253     public function render(OutputInterface $output)
254     {
255         $p = new \ReflectionProperty($this->table, 'output');
256         $p->setAccessible(true);
257         $p->setValue($this->table, $output);
258
259         $this->table->render();
260     }
261
262     /**
263      * {@inheritdoc}
264      */
265     public function getName()
266     {
267         return 'table';
268     }
269 }