TableCell.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if (is_numeric($value) && !is_string($value)) {
  35. $value = (string) $value;
  36. }
  37. $this->value = $value;
  38. // check option names
  39. if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  40. throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  41. }
  42. $this->options = array_merge($this->options, $options);
  43. }
  44. /**
  45. * Returns the cell value.
  46. *
  47. * @return string
  48. */
  49. public function __toString()
  50. {
  51. return $this->value;
  52. }
  53. /**
  54. * Gets number of colspan.
  55. *
  56. * @return int
  57. */
  58. public function getColspan()
  59. {
  60. return (int) $this->options['colspan'];
  61. }
  62. /**
  63. * Gets number of rowspan.
  64. *
  65. * @return int
  66. */
  67. public function getRowspan()
  68. {
  69. return (int) $this->options['rowspan'];
  70. }
  71. }