PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Helper / TableCellStyle.php

TableCellStyle.php in Depicter — Popup & Slider Builder trunk, at vendor/symfony/console/Helper/TableCellStyle.php

90 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
16 /**
17 * @author Yewhen Khoptynskyi <khoptynskyi@gmail.com>
18 */
19 class 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 $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()
67 {
68 return array_filter(
69 $this->getOptions(),
70 function ($key) {
71 return \in_array($key, self::TAG_OPTIONS) && isset($this->options[$key]);
72 },
73 \ARRAY_FILTER_USE_KEY
74 );
75 }
76
77 /**
78 * @return int
79 */
80 public function getPadByAlign()
81 {
82 return self::ALIGN_MAP[$this->getOptions()['align']];
83 }
84
85 public function getCellFormat(): ?string
86 {
87 return $this->getOptions()['cellFormat'];
88 }
89 }
90