Debian Codegraph @

vendor/symfony/console/Helper/TableCell.php

raw
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 Abdellatif Ait boudad <[email protected]>
18 */
19 class TableCell
20 {
21 private array $options = [
22 'rowspan' => 1,
23 'colspan' => 1,
24 'style' => null,
25 ];
26
27 public function __construct(
28 private string $value = '',
29 array $options = [],
30 ) {
31 // check option names
32 if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
33 throw new InvalidArgumentException(\sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
34 }
35
36 if (isset($options['style']) && !$options['style'] instanceof TableCellStyle) {
37 throw new InvalidArgumentException('The style option must be an instance of "TableCellStyle".');
38 }
39
40 $this->options = array_merge($this->options, $options);
41 }
42
43 /**
44 * Returns the cell value.
45 */
46 public function __toString(): string
47 {
48 return $this->value;
49 }
50
51 /**
52 * Gets number of colspan.
53 */
54 public function getColspan(): int
55 {
56 return (int) $this->options['colspan'];
57 }
58
59 /**
60 * Gets number of rowspan.
61 */
62 public function getRowspan(): int
63 {
64 return (int) $this->options['rowspan'];
65 }
66
67 public function getStyle(): ?TableCellStyle
68 {
69 return $this->options['style'];
70 }
71 }