TextElement.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\RichText;
  3. class TextElement implements ITextElement
  4. {
  5. /**
  6. * Text.
  7. *
  8. * @var string
  9. */
  10. private $text;
  11. /**
  12. * Create a new TextElement instance.
  13. *
  14. * @param string $pText Text
  15. */
  16. public function __construct($pText = '')
  17. {
  18. // Initialise variables
  19. $this->text = $pText;
  20. }
  21. /**
  22. * Get text.
  23. *
  24. * @return string Text
  25. */
  26. public function getText()
  27. {
  28. return $this->text;
  29. }
  30. /**
  31. * Set text.
  32. *
  33. * @param $text string Text
  34. *
  35. * @return ITextElement
  36. */
  37. public function setText($text)
  38. {
  39. $this->text = $text;
  40. return $this;
  41. }
  42. /**
  43. * Get font.
  44. *
  45. * @return \PhpOffice\PhpSpreadsheet\Style\Font
  46. */
  47. public function getFont()
  48. {
  49. return null;
  50. }
  51. /**
  52. * Get hash code.
  53. *
  54. * @return string Hash code
  55. */
  56. public function getHashCode()
  57. {
  58. return md5(
  59. $this->text .
  60. __CLASS__
  61. );
  62. }
  63. /**
  64. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  65. */
  66. public function __clone()
  67. {
  68. $vars = get_object_vars($this);
  69. foreach ($vars as $key => $value) {
  70. if (is_object($value)) {
  71. $this->$key = clone $value;
  72. } else {
  73. $this->$key = $value;
  74. }
  75. }
  76. }
  77. }