| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 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 |
|
| 19 |
|
| 20 |
|
| 21 |
[email protected]> |
| 22 |
|
| 23 |
|
| 24 |
class TableStyle |
| 25 |
{ |
| 26 |
private string $paddingChar = ' '; |
| 27 |
private string $horizontalOutsideBorderChar = '-'; |
| 28 |
private string $horizontalInsideBorderChar = '-'; |
| 29 |
private string $verticalOutsideBorderChar = '|'; |
| 30 |
private string $verticalInsideBorderChar = '|'; |
| 31 |
private string $crossingChar = '+'; |
| 32 |
private string $crossingTopRightChar = '+'; |
| 33 |
private string $crossingTopMidChar = '+'; |
| 34 |
private string $crossingTopLeftChar = '+'; |
| 35 |
private string $crossingMidRightChar = '+'; |
| 36 |
private string $crossingBottomRightChar = '+'; |
| 37 |
private string $crossingBottomMidChar = '+'; |
| 38 |
private string $crossingBottomLeftChar = '+'; |
| 39 |
private string $crossingMidLeftChar = '+'; |
| 40 |
private string $crossingTopLeftBottomChar = '+'; |
| 41 |
private string $crossingTopMidBottomChar = '+'; |
| 42 |
private string $crossingTopRightBottomChar = '+'; |
| 43 |
private string $headerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
| 44 |
private string $footerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
| 45 |
private string $cellHeaderFormat = '<info>%s</info>'; |
| 46 |
private string $cellRowFormat = '%s'; |
| 47 |
private string $cellRowContentFormat = ' %s '; |
| 48 |
private string $borderFormat = '%s'; |
| 49 |
private bool $displayOutsideBorder = true; |
| 50 |
private int $padType = \STR_PAD_RIGHT; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public function setPaddingChar(string $paddingChar): static |
| 58 |
{ |
| 59 |
if (!$paddingChar) { |
| 60 |
throw new LogicException('The padding char must not be empty.'); |
| 61 |
} |
| 62 |
|
| 63 |
$this->paddingChar = $paddingChar; |
| 64 |
|
| 65 |
return $this; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function getPaddingChar(): string |
| 72 |
{ |
| 73 |
return $this->paddingChar; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
══════════════════════╤══════════════════╗ |
| 81 |
║ |
| 82 |
══════════════════════╪══════════════════╣ |
| 83 |
eri ║ |
| 84 |
ens ║ |
| 85 |
──────────────────────┼──────────────────╢ |
| 86 |
kien ║ |
| 87 |
tie ║ |
| 88 |
══════════════════════╧══════════════════╝ |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public function setHorizontalBorderChars(string $outside, ?string $inside = null): static |
| 94 |
{ |
| 95 |
$this->horizontalOutsideBorderChar = $outside; |
| 96 |
$this->horizontalInsideBorderChar = $inside ?? $outside; |
| 97 |
|
| 98 |
return $this; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
══════════════════════╤══════════════════╗ |
| 106 |
║ |
| 107 |
══════════════════════╪══════════════════╣ |
| 108 |
eri ║ |
| 109 |
ens ║ |
| 110 |
kien ║ |
| 111 |
tie ║ |
| 112 |
══════════════════════╧══════════════════╝ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function setVerticalBorderChars(string $outside, ?string $inside = null): static |
| 118 |
{ |
| 119 |
$this->verticalOutsideBorderChar = $outside; |
| 120 |
$this->verticalInsideBorderChar = $inside ?? $outside; |
| 121 |
|
| 122 |
return $this; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public function getBorderChars(): array |
| 131 |
{ |
| 132 |
return [ |
| 133 |
$this->horizontalOutsideBorderChar, |
| 134 |
$this->verticalOutsideBorderChar, |
| 135 |
$this->horizontalInsideBorderChar, |
| 136 |
$this->verticalInsideBorderChar, |
| 137 |
]; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
═════════════════════2══════════════════3 |
| 146 |
║ |
| 147 |
═══════════════════0'═════════════════4' |
| 148 |
eri ║ |
| 149 |
ens ║ |
| 150 |
─────────────────────0──────────────────4 |
| 151 |
kien ║ |
| 152 |
tie ║ |
| 153 |
═════════════════════6══════════════════5 |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, ?string $topLeftBottom = null, ?string $topMidBottom = null, ?string $topRightBottom = null): static |
| 172 |
{ |
| 173 |
$this->crossingChar = $cross; |
| 174 |
$this->crossingTopLeftChar = $topLeft; |
| 175 |
$this->crossingTopMidChar = $topMid; |
| 176 |
$this->crossingTopRightChar = $topRight; |
| 177 |
$this->crossingMidRightChar = $midRight; |
| 178 |
$this->crossingBottomRightChar = $bottomRight; |
| 179 |
$this->crossingBottomMidChar = $bottomMid; |
| 180 |
$this->crossingBottomLeftChar = $bottomLeft; |
| 181 |
$this->crossingMidLeftChar = $midLeft; |
| 182 |
$this->crossingTopLeftBottomChar = $topLeftBottom ?? $midLeft; |
| 183 |
$this->crossingTopMidBottomChar = $topMidBottom ?? $cross; |
| 184 |
$this->crossingTopRightBottomChar = $topRightBottom ?? $midRight; |
| 185 |
|
| 186 |
return $this; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public function setDefaultCrossingChar(string $char): self |
| 195 |
{ |
| 196 |
return $this->setCrossingChars($char, $char, $char, $char, $char, $char, $char, $char, $char); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public function getCrossingChar(): string |
| 203 |
{ |
| 204 |
return $this->crossingChar; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public function getCrossingChars(): array |
| 213 |
{ |
| 214 |
return [ |
| 215 |
$this->crossingChar, |
| 216 |
$this->crossingTopLeftChar, |
| 217 |
$this->crossingTopMidChar, |
| 218 |
$this->crossingTopRightChar, |
| 219 |
$this->crossingMidRightChar, |
| 220 |
$this->crossingBottomRightChar, |
| 221 |
$this->crossingBottomMidChar, |
| 222 |
$this->crossingBottomLeftChar, |
| 223 |
$this->crossingMidLeftChar, |
| 224 |
$this->crossingTopLeftBottomChar, |
| 225 |
$this->crossingTopMidBottomChar, |
| 226 |
$this->crossingTopRightBottomChar, |
| 227 |
]; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public function setCellHeaderFormat(string $cellHeaderFormat): static |
| 236 |
{ |
| 237 |
$this->cellHeaderFormat = $cellHeaderFormat; |
| 238 |
|
| 239 |
return $this; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public function getCellHeaderFormat(): string |
| 246 |
{ |
| 247 |
return $this->cellHeaderFormat; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
public function setCellRowFormat(string $cellRowFormat): static |
| 256 |
{ |
| 257 |
$this->cellRowFormat = $cellRowFormat; |
| 258 |
|
| 259 |
return $this; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
public function getCellRowFormat(): string |
| 266 |
{ |
| 267 |
return $this->cellRowFormat; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public function setCellRowContentFormat(string $cellRowContentFormat): static |
| 276 |
{ |
| 277 |
$this->cellRowContentFormat = $cellRowContentFormat; |
| 278 |
|
| 279 |
return $this; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public function getCellRowContentFormat(): string |
| 286 |
{ |
| 287 |
return $this->cellRowContentFormat; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
public function setBorderFormat(string $borderFormat): static |
| 296 |
{ |
| 297 |
$this->borderFormat = $borderFormat; |
| 298 |
|
| 299 |
return $this; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
public function getBorderFormat(): string |
| 306 |
{ |
| 307 |
return $this->borderFormat; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
public function setPadType(int $padType): static |
| 316 |
{ |
| 317 |
if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) { |
| 318 |
throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); |
| 319 |
} |
| 320 |
|
| 321 |
$this->padType = $padType; |
| 322 |
|
| 323 |
return $this; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public function getPadType(): int |
| 330 |
{ |
| 331 |
return $this->padType; |
| 332 |
} |
| 333 |
|
| 334 |
public function getHeaderTitleFormat(): string |
| 335 |
{ |
| 336 |
return $this->headerTitleFormat; |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public function setHeaderTitleFormat(string $format): static |
| 343 |
{ |
| 344 |
$this->headerTitleFormat = $format; |
| 345 |
|
| 346 |
return $this; |
| 347 |
} |
| 348 |
|
| 349 |
public function getFooterTitleFormat(): string |
| 350 |
{ |
| 351 |
return $this->footerTitleFormat; |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
public function setFooterTitleFormat(string $format): static |
| 358 |
{ |
| 359 |
$this->footerTitleFormat = $format; |
| 360 |
|
| 361 |
return $this; |
| 362 |
} |
| 363 |
|
| 364 |
public function setDisplayOutsideBorder($displayOutSideBorder): static |
| 365 |
{ |
| 366 |
$this->displayOutsideBorder = $displayOutSideBorder; |
| 367 |
|
| 368 |
return $this; |
| 369 |
} |
| 370 |
|
| 371 |
public function displayOutsideBorder(): bool |
| 372 |
{ |
| 373 |
return $this->displayOutsideBorder; |
| 374 |
} |
| 375 |
} |