Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Console\Helper;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\Console\Exception\InvalidArgumentException;
|
Chris@0
|
15 use Symfony\Component\Console\Exception\LogicException;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Defines the styles for a Table.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
21 * @author Саша Стаменковић <umpirsky@gmail.com>
|
Chris@0
|
22 */
|
Chris@0
|
23 class TableStyle
|
Chris@0
|
24 {
|
Chris@0
|
25 private $paddingChar = ' ';
|
Chris@0
|
26 private $horizontalBorderChar = '-';
|
Chris@0
|
27 private $verticalBorderChar = '|';
|
Chris@0
|
28 private $crossingChar = '+';
|
Chris@0
|
29 private $cellHeaderFormat = '<info>%s</info>';
|
Chris@0
|
30 private $cellRowFormat = '%s';
|
Chris@0
|
31 private $cellRowContentFormat = ' %s ';
|
Chris@0
|
32 private $borderFormat = '%s';
|
Chris@0
|
33 private $padType = STR_PAD_RIGHT;
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * Sets padding character, used for cell padding.
|
Chris@0
|
37 *
|
Chris@0
|
38 * @param string $paddingChar
|
Chris@0
|
39 *
|
Chris@0
|
40 * @return $this
|
Chris@0
|
41 */
|
Chris@0
|
42 public function setPaddingChar($paddingChar)
|
Chris@0
|
43 {
|
Chris@0
|
44 if (!$paddingChar) {
|
Chris@0
|
45 throw new LogicException('The padding char must not be empty');
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 $this->paddingChar = $paddingChar;
|
Chris@0
|
49
|
Chris@0
|
50 return $this;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Gets padding character, used for cell padding.
|
Chris@0
|
55 *
|
Chris@0
|
56 * @return string
|
Chris@0
|
57 */
|
Chris@0
|
58 public function getPaddingChar()
|
Chris@0
|
59 {
|
Chris@0
|
60 return $this->paddingChar;
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 /**
|
Chris@0
|
64 * Sets horizontal border character.
|
Chris@0
|
65 *
|
Chris@0
|
66 * @param string $horizontalBorderChar
|
Chris@0
|
67 *
|
Chris@0
|
68 * @return $this
|
Chris@0
|
69 */
|
Chris@0
|
70 public function setHorizontalBorderChar($horizontalBorderChar)
|
Chris@0
|
71 {
|
Chris@0
|
72 $this->horizontalBorderChar = $horizontalBorderChar;
|
Chris@0
|
73
|
Chris@0
|
74 return $this;
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 /**
|
Chris@0
|
78 * Gets horizontal border character.
|
Chris@0
|
79 *
|
Chris@0
|
80 * @return string
|
Chris@0
|
81 */
|
Chris@0
|
82 public function getHorizontalBorderChar()
|
Chris@0
|
83 {
|
Chris@0
|
84 return $this->horizontalBorderChar;
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 /**
|
Chris@0
|
88 * Sets vertical border character.
|
Chris@0
|
89 *
|
Chris@0
|
90 * @param string $verticalBorderChar
|
Chris@0
|
91 *
|
Chris@0
|
92 * @return $this
|
Chris@0
|
93 */
|
Chris@0
|
94 public function setVerticalBorderChar($verticalBorderChar)
|
Chris@0
|
95 {
|
Chris@0
|
96 $this->verticalBorderChar = $verticalBorderChar;
|
Chris@0
|
97
|
Chris@0
|
98 return $this;
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Gets vertical border character.
|
Chris@0
|
103 *
|
Chris@0
|
104 * @return string
|
Chris@0
|
105 */
|
Chris@0
|
106 public function getVerticalBorderChar()
|
Chris@0
|
107 {
|
Chris@0
|
108 return $this->verticalBorderChar;
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@0
|
111 /**
|
Chris@0
|
112 * Sets crossing character.
|
Chris@0
|
113 *
|
Chris@0
|
114 * @param string $crossingChar
|
Chris@0
|
115 *
|
Chris@0
|
116 * @return $this
|
Chris@0
|
117 */
|
Chris@0
|
118 public function setCrossingChar($crossingChar)
|
Chris@0
|
119 {
|
Chris@0
|
120 $this->crossingChar = $crossingChar;
|
Chris@0
|
121
|
Chris@0
|
122 return $this;
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 /**
|
Chris@0
|
126 * Gets crossing character.
|
Chris@0
|
127 *
|
Chris@17
|
128 * @return string
|
Chris@0
|
129 */
|
Chris@0
|
130 public function getCrossingChar()
|
Chris@0
|
131 {
|
Chris@0
|
132 return $this->crossingChar;
|
Chris@0
|
133 }
|
Chris@0
|
134
|
Chris@0
|
135 /**
|
Chris@0
|
136 * Sets header cell format.
|
Chris@0
|
137 *
|
Chris@0
|
138 * @param string $cellHeaderFormat
|
Chris@0
|
139 *
|
Chris@0
|
140 * @return $this
|
Chris@0
|
141 */
|
Chris@0
|
142 public function setCellHeaderFormat($cellHeaderFormat)
|
Chris@0
|
143 {
|
Chris@0
|
144 $this->cellHeaderFormat = $cellHeaderFormat;
|
Chris@0
|
145
|
Chris@0
|
146 return $this;
|
Chris@0
|
147 }
|
Chris@0
|
148
|
Chris@0
|
149 /**
|
Chris@0
|
150 * Gets header cell format.
|
Chris@0
|
151 *
|
Chris@0
|
152 * @return string
|
Chris@0
|
153 */
|
Chris@0
|
154 public function getCellHeaderFormat()
|
Chris@0
|
155 {
|
Chris@0
|
156 return $this->cellHeaderFormat;
|
Chris@0
|
157 }
|
Chris@0
|
158
|
Chris@0
|
159 /**
|
Chris@0
|
160 * Sets row cell format.
|
Chris@0
|
161 *
|
Chris@0
|
162 * @param string $cellRowFormat
|
Chris@0
|
163 *
|
Chris@0
|
164 * @return $this
|
Chris@0
|
165 */
|
Chris@0
|
166 public function setCellRowFormat($cellRowFormat)
|
Chris@0
|
167 {
|
Chris@0
|
168 $this->cellRowFormat = $cellRowFormat;
|
Chris@0
|
169
|
Chris@0
|
170 return $this;
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@0
|
173 /**
|
Chris@0
|
174 * Gets row cell format.
|
Chris@0
|
175 *
|
Chris@0
|
176 * @return string
|
Chris@0
|
177 */
|
Chris@0
|
178 public function getCellRowFormat()
|
Chris@0
|
179 {
|
Chris@0
|
180 return $this->cellRowFormat;
|
Chris@0
|
181 }
|
Chris@0
|
182
|
Chris@0
|
183 /**
|
Chris@0
|
184 * Sets row cell content format.
|
Chris@0
|
185 *
|
Chris@0
|
186 * @param string $cellRowContentFormat
|
Chris@0
|
187 *
|
Chris@0
|
188 * @return $this
|
Chris@0
|
189 */
|
Chris@0
|
190 public function setCellRowContentFormat($cellRowContentFormat)
|
Chris@0
|
191 {
|
Chris@0
|
192 $this->cellRowContentFormat = $cellRowContentFormat;
|
Chris@0
|
193
|
Chris@0
|
194 return $this;
|
Chris@0
|
195 }
|
Chris@0
|
196
|
Chris@0
|
197 /**
|
Chris@0
|
198 * Gets row cell content format.
|
Chris@0
|
199 *
|
Chris@0
|
200 * @return string
|
Chris@0
|
201 */
|
Chris@0
|
202 public function getCellRowContentFormat()
|
Chris@0
|
203 {
|
Chris@0
|
204 return $this->cellRowContentFormat;
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 /**
|
Chris@0
|
208 * Sets table border format.
|
Chris@0
|
209 *
|
Chris@0
|
210 * @param string $borderFormat
|
Chris@0
|
211 *
|
Chris@0
|
212 * @return $this
|
Chris@0
|
213 */
|
Chris@0
|
214 public function setBorderFormat($borderFormat)
|
Chris@0
|
215 {
|
Chris@0
|
216 $this->borderFormat = $borderFormat;
|
Chris@0
|
217
|
Chris@0
|
218 return $this;
|
Chris@0
|
219 }
|
Chris@0
|
220
|
Chris@0
|
221 /**
|
Chris@0
|
222 * Gets table border format.
|
Chris@0
|
223 *
|
Chris@0
|
224 * @return string
|
Chris@0
|
225 */
|
Chris@0
|
226 public function getBorderFormat()
|
Chris@0
|
227 {
|
Chris@0
|
228 return $this->borderFormat;
|
Chris@0
|
229 }
|
Chris@0
|
230
|
Chris@0
|
231 /**
|
Chris@0
|
232 * Sets cell padding type.
|
Chris@0
|
233 *
|
Chris@0
|
234 * @param int $padType STR_PAD_*
|
Chris@0
|
235 *
|
Chris@0
|
236 * @return $this
|
Chris@0
|
237 */
|
Chris@0
|
238 public function setPadType($padType)
|
Chris@0
|
239 {
|
Chris@17
|
240 if (!\in_array($padType, [STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH], true)) {
|
Chris@0
|
241 throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
|
Chris@0
|
242 }
|
Chris@0
|
243
|
Chris@0
|
244 $this->padType = $padType;
|
Chris@0
|
245
|
Chris@0
|
246 return $this;
|
Chris@0
|
247 }
|
Chris@0
|
248
|
Chris@0
|
249 /**
|
Chris@0
|
250 * Gets cell padding type.
|
Chris@0
|
251 *
|
Chris@0
|
252 * @return int
|
Chris@0
|
253 */
|
Chris@0
|
254 public function getPadType()
|
Chris@0
|
255 {
|
Chris@0
|
256 return $this->padType;
|
Chris@0
|
257 }
|
Chris@0
|
258 }
|