TableCell.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  12. * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
  13. */
  14. class TableCell
  15. {
  16. /**
  17. * @var string
  18. */
  19. private $value;
  20. /**
  21. * @var array
  22. */
  23. private $options = array(
  24. 'rowspan' => 1,
  25. 'colspan' => 1,
  26. );
  27. /**
  28. * @param string $value
  29. * @param array $options
  30. */
  31. public function __construct($value = '', array $options = array())
  32. {
  33. $this->value = $value;
  34. // check option names
  35. if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  36. throw new \InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  37. }
  38. $this->options = array_merge($this->options, $options);
  39. }
  40. /**
  41. * Returns the cell value.
  42. *
  43. * @return string
  44. */
  45. public function __toString()
  46. {
  47. return $this->value;
  48. }
  49. /**
  50. * Gets number of colspan.
  51. *
  52. * @return int
  53. */
  54. public function getColspan()
  55. {
  56. return (int) $this->options['colspan'];
  57. }
  58. /**
  59. * Gets number of rowspan.
  60. *
  61. * @return int
  62. */
  63. public function getRowspan()
  64. {
  65. return (int) $this->options['rowspan'];
  66. }
  67. }