TableCell.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. ];
  22. public function __construct(string $value = '', array $options = [])
  23. {
  24. $this->value = $value;
  25. // check option names
  26. if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  27. throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  28. }
  29. $this->options = array_merge($this->options, $options);
  30. }
  31. /**
  32. * Returns the cell value.
  33. *
  34. * @return string
  35. */
  36. public function __toString()
  37. {
  38. return $this->value;
  39. }
  40. /**
  41. * Gets number of colspan.
  42. *
  43. * @return int
  44. */
  45. public function getColspan()
  46. {
  47. return (int) $this->options['colspan'];
  48. }
  49. /**
  50. * Gets number of rowspan.
  51. *
  52. * @return int
  53. */
  54. public function getRowspan()
  55. {
  56. return (int) $this->options['rowspan'];
  57. }
  58. }