TableCell.php 1.6 KB

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