TableCell.php 1.8 KB

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