菜谱项目

TableCell.php 1.6KB

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