Link.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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\Font;
  20. use PhpOffice\PhpWord\Style\Paragraph;
  21. /**
  22. * Link element
  23. */
  24. class Link extends AbstractElement
  25. {
  26. /**
  27. * Link source
  28. *
  29. * @var string
  30. */
  31. private $source;
  32. /**
  33. * Link text
  34. *
  35. * @var string
  36. */
  37. private $text;
  38. /**
  39. * Font style
  40. *
  41. * @var string|\PhpOffice\PhpWord\Style\Font
  42. */
  43. private $fontStyle;
  44. /**
  45. * Paragraph style
  46. *
  47. * @var string|\PhpOffice\PhpWord\Style\Paragraph
  48. */
  49. private $paragraphStyle;
  50. /**
  51. * Has media relation flag; true for Link, Image, and Object
  52. *
  53. * @var bool
  54. */
  55. protected $mediaRelation = true;
  56. /**
  57. * Has internal flag - anchor to internal bookmark
  58. *
  59. * @var bool
  60. */
  61. protected $internal = false;
  62. /**
  63. * Create a new Link Element
  64. *
  65. * @param string $source
  66. * @param string $text
  67. * @param mixed $fontStyle
  68. * @param mixed $paragraphStyle
  69. * @param bool $internal
  70. */
  71. public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
  72. {
  73. $this->source = SharedText::toUTF8($source);
  74. $this->text = is_null($text) ? $this->source : SharedText::toUTF8($text);
  75. $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
  76. $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
  77. $this->internal = $internal;
  78. }
  79. /**
  80. * Get link source
  81. *
  82. * @return string
  83. */
  84. public function getSource()
  85. {
  86. return $this->source;
  87. }
  88. /**
  89. * Get link text
  90. *
  91. * @return string
  92. */
  93. public function getText()
  94. {
  95. return $this->text;
  96. }
  97. /**
  98. * Get Text style
  99. *
  100. * @return string|\PhpOffice\PhpWord\Style\Font
  101. */
  102. public function getFontStyle()
  103. {
  104. return $this->fontStyle;
  105. }
  106. /**
  107. * Get Paragraph style
  108. *
  109. * @return string|\PhpOffice\PhpWord\Style\Paragraph
  110. */
  111. public function getParagraphStyle()
  112. {
  113. return $this->paragraphStyle;
  114. }
  115. /**
  116. * Get link target
  117. *
  118. * @deprecated 0.12.0
  119. *
  120. * @return string
  121. *
  122. * @codeCoverageIgnore
  123. */
  124. public function getTarget()
  125. {
  126. return $this->source;
  127. }
  128. /**
  129. * Get Link source
  130. *
  131. * @deprecated 0.10.0
  132. *
  133. * @return string
  134. *
  135. * @codeCoverageIgnore
  136. */
  137. public function getLinkSrc()
  138. {
  139. return $this->getSource();
  140. }
  141. /**
  142. * Get Link name
  143. *
  144. * @deprecated 0.10.0
  145. *
  146. * @return string
  147. *
  148. * @codeCoverageIgnore
  149. */
  150. public function getLinkName()
  151. {
  152. return $this->getText();
  153. }
  154. /**
  155. * is internal
  156. *
  157. * @return bool
  158. */
  159. public function isInternal()
  160. {
  161. return $this->internal;
  162. }
  163. }