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