summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Helper/TableCellStyle.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/console/Helper/TableCellStyle.php')
-rw-r--r--vendor/symfony/console/Helper/TableCellStyle.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/symfony/console/Helper/TableCellStyle.php b/vendor/symfony/console/Helper/TableCellStyle.php
new file mode 100644
index 0000000..49b97f8
--- /dev/null
+++ b/vendor/symfony/console/Helper/TableCellStyle.php
@@ -0,0 +1,84 @@
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
12namespace Symfony\Component\Console\Helper;
13
14use Symfony\Component\Console\Exception\InvalidArgumentException;
15
16/**
17 * @author Yewhen Khoptynskyi <khoptynskyi@gmail.com>
18 */
19class TableCellStyle
20{
21 public const DEFAULT_ALIGN = 'left';
22
23 private const TAG_OPTIONS = [
24 'fg',
25 'bg',
26 'options',
27 ];
28
29 private const ALIGN_MAP = [
30 'left' => \STR_PAD_RIGHT,
31 'center' => \STR_PAD_BOTH,
32 'right' => \STR_PAD_LEFT,
33 ];
34
35 private array $options = [
36 'fg' => 'default',
37 'bg' => 'default',
38 'options' => null,
39 'align' => self::DEFAULT_ALIGN,
40 'cellFormat' => null,
41 ];
42
43 public function __construct(array $options = [])
44 {
45 if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
46 throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff)));
47 }
48
49 if (isset($options['align']) && !\array_key_exists($options['align'], self::ALIGN_MAP)) {
50 throw new InvalidArgumentException(sprintf('Wrong align value. Value must be following: \'%s\'.', implode('\', \'', array_keys(self::ALIGN_MAP))));
51 }
52
53 $this->options = array_merge($this->options, $options);
54 }
55
56 public function getOptions(): array
57 {
58 return $this->options;
59 }
60
61 /**
62 * Gets options we need for tag for example fg, bg.
63 *
64 * @return string[]
65 */
66 public function getTagOptions(): array
67 {
68 return array_filter(
69 $this->getOptions(),
70 fn ($key) => \in_array($key, self::TAG_OPTIONS, true) && isset($this->options[$key]),
71 \ARRAY_FILTER_USE_KEY
72 );
73 }
74
75 public function getPadByAlign(): int
76 {
77 return self::ALIGN_MAP[$this->getOptions()['align']];
78 }
79
80 public function getCellFormat(): ?string
81 {
82 return $this->getOptions()['cellFormat'];
83 }
84}