TableCell.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Helper;
  11. use Symfony\Component\Console\Exception\InvalidArgumentException;
  12. /**
  13. * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
  14. */
  15. class TableCell
  16. {
  17. private $value;
  18. private $options = [
  19. 'rowspan' => 1,
  20. 'colspan' => 1,
  21. 'style' => null,
  22. ];
  23. public function __construct(string $value = '', array $options = [])
  24. {
  25. $this->value = $value;
  26. // check option names
  27. if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  28. throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  29. }
  30. if (isset($options['style']) && !$options['style'] instanceof TableCellStyle) {
  31. throw new InvalidArgumentException('The style option must be an instance of "TableCellStyle".');
  32. }
  33. $this->options = array_merge($this->options, $options);
  34. }
  35. /**
  36. * Returns the cell value.
  37. *
  38. * @return string
  39. */
  40. public function __toString()
  41. {
  42. return $this->value;
  43. }
  44. /**
  45. * Gets number of colspan.
  46. *
  47. * @return int
  48. */
  49. public function getColspan()
  50. {
  51. return (int) $this->options['colspan'];
  52. }
  53. /**
  54. * Gets number of rowspan.
  55. *
  56. * @return int
  57. */
  58. public function getRowspan()
  59. {
  60. return (int) $this->options['rowspan'];
  61. }
  62. public function getStyle(): ?TableCellStyle
  63. {
  64. return $this->options['style'];
  65. }
  66. }