ListItem.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @see https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2018 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. use PhpOffice\PhpWord\Shared\Text as SharedText;
  19. use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
  20. /**
  21. * List item element
  22. */
  23. class ListItem extends AbstractElement
  24. {
  25. /**
  26. * Element style
  27. *
  28. * @var \PhpOffice\PhpWord\Style\ListItem
  29. */
  30. private $style;
  31. /**
  32. * Text object
  33. *
  34. * @var \PhpOffice\PhpWord\Element\Text
  35. */
  36. private $textObject;
  37. /**
  38. * Depth
  39. *
  40. * @var int
  41. */
  42. private $depth;
  43. /**
  44. * Create a new ListItem
  45. *
  46. * @param string $text
  47. * @param int $depth
  48. * @param mixed $fontStyle
  49. * @param array|string|null $listStyle
  50. * @param mixed $paragraphStyle
  51. */
  52. public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
  53. {
  54. $this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle);
  55. $this->depth = $depth;
  56. // Version >= 0.10.0 will pass numbering style name. Older version will use old method
  57. if (!is_null($listStyle) && is_string($listStyle)) {
  58. $this->style = new ListItemStyle($listStyle); // @codeCoverageIgnore
  59. } else {
  60. $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
  61. }
  62. }
  63. /**
  64. * Get style
  65. *
  66. * @return \PhpOffice\PhpWord\Style\ListItem
  67. */
  68. public function getStyle()
  69. {
  70. return $this->style;
  71. }
  72. /**
  73. * Get Text object
  74. *
  75. * @return \PhpOffice\PhpWord\Element\Text
  76. */
  77. public function getTextObject()
  78. {
  79. return $this->textObject;
  80. }
  81. /**
  82. * Get depth
  83. *
  84. * @return int
  85. */
  86. public function getDepth()
  87. {
  88. return $this->depth;
  89. }
  90. /**
  91. * Get text
  92. *
  93. * @return string
  94. * @since 0.11.0
  95. */
  96. public function getText()
  97. {
  98. return $this->textObject->getText();
  99. }
  100. }